Intermediate Algorithm Scripting: Convert HTML Entities (BUG?)

Intermediate Algorithm Scripting: Convert HTML Entities (BUG?)
0

#1

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:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities/


#2

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.


#3

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


#4

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.


#5

A post was split to a new topic: Not passing a test on convert html entities challenges