Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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, '');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading