How to make a const value work in this if-statement

Advertisements

I have been trying to make the text from a raw github file test if the text is also the same as put in the if statement. It doesn’t seem to work and the code runs the code in the if statement no matter what.

var current_version = "b-1"

const url = 'https://raw.githubusercontent.com/MythicalTrashcan/MY-Javascript-Bookmarklets/main/Version%20ID'
const version = await fetch(url);
const data = await version.text();

if (current_version != data) {
    alert("Outated Bookmarklet!");
}

I was expecting the value to check if b-1 is not equal to the raw github to see if it would run that code inside the if-statement or not.

>Solution :

Based on your code, github returns with new line ending

So remove that \n, the code works

const data = (await version.text()).replace(/\n+/g, '');

Leave a ReplyCancel reply