Convert HTML Entities weird issue

Tell us what’s happening:
The output I am getting on console is correct but it isn’t getting validated on tests, why?

Your code so far


function convertHTML(str) {
  // :)
  var arr=str.split("")
  arr.forEach((x,i)=>{
    var elem = x;
    switch(x){
      case '&': elem="&​amp;";break;
      case '<': elem="&​lt;";break;
      case '>': elem="&​gt;";break;
      case '\'': elem="&​apos;";break;
      case '"': elem="&​quot;";break;
    }
    arr[i]=elem
  })
  str = arr.join("")
  console.log(str)
  return str;
}

convertHTML("Dolce & Gabbana");
convertHTML("Hamburgers < Pizza < Tacos")
convertHTML("Sixty > twelve")
convertHTML('Stuff in "quotation marks"')
convertHTML("Schindler's List")
convertHTML("<>")

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36.

Type the entity codes (eg &amp;) out rather an copy pasting. There’s a hidden character in each one after the & — if you look at them in the browser console you’ll be able to see it as a red dot.

2 Likes