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

Time:01-31

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 ID'
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.

CodePudding user response:

Based on your code, github returns with new line ending

enter image description here

So remove that \n, the code works

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