Convert HTML Entities | Problem with if-else

Hi, all

I’m trying to figure my solution for the Algorithm Scripting | Convert HTML Entities challenge and since i like using if else to figure solution for this challenge i do it with it but, when i click Run test … It doesn’t work !!!

this is my code :

function convertHTML(str) {

  let newstr = str.split('') 

  for (let i = 0; i < newstr.length; i++) {
    if (newstr[i] == '&') {
    newstr[i] = '&​amp;';
    }
    else if (newstr[i] == '<') {
    newstr[i] = '&​lt';
    }
    else if (newstr[i] == '>') {
    newstr[i] = '&​gt;'
    }
    else if (newstr[i] == '"') {
    newstr[i] = '&​quot;';
    }
    else if (newstr[i] == "'") {
    newstr[i] = '&​apos;';
    }
  }
  newstr = newstr.join('');
  return newstr;
}
console.log(convertHTML("Dolce & Gabbana")) // Dolce &​amp; Gabbana

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities

Thanks :blush:

1 Like

if you have copied and pasted these there may be an hidden character in there, which is deleted but the tests and so the tests fail (next curriculum update this should be fixed)
try deleting and typing them

Yes, i copied it but,because when i wrote it directly … it didn’t work and give me that in the console

console.log(convertHTML("Dolce & Gabbana")) // Dolce & Gabbana

OK , thanks. It’s work now :grinning: