Intermediate Algorithm Scripting: Convert HTML Entities (BUG?)

Tell us what’s happening:
So this code is not working on freeCodeCamp, although I get the right output on repl.it…

Your code so far


function convertHTML(str) {
  // :)

  let temp = str.split("");
   
  for (let i = 0; i < temp.length; i++) {

    switch(temp[i]) {
      
      case "&":
        temp[i] = "&​amp;";
        break;
      case "<":
        temp[i] = "&​lt;";
        break;
      case ">":
        temp[i] = "&​gt;";
        break;
      case '"':
        temp[i] = "&​quot;";
        break;
      case "'":
        temp[i] = "&​apos;";
        break;

    }
  }
  temp = temp.join("");
  return temp;
}

convertHTML("Dolce & Gabbana");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0.

Link to the challenge:

Your code contains hidden characters. Paste it here: https://stephengrider.github.io/JSPlaygrounds/

Then remove the dots that follow the & characters and repaste into FCC.

6 Likes

Thank you very much :wink: How did you figure this out?

I usually use the repl at https://stephengrider.github.io/JSPlaygrounds/ to check code. When I pasted your code in, I noticed the extra ‘dot’ characters appearing, that’s all.

Dude, this works like a charm…Strange that these hidden characters are not caught by other editors.

omg thank you it worked!