Convert HTML Entities please help

Can’t find the mistake

Your code so far

[spoiler]function convertHTML(str) {
  var x= str.split('');
  for (var i=0; i< x.length; i++){
    switch (x[i]){
    case '&':
    x[i]='&amp;';
    break;
    case '<':
    x[i]='&​lt;';
    break;
    case '>':
    x[i]='&​gt;';
    break;
    case '"':
    x[i]='&​quot;';
    break;
    case "'":
    x[i]='&​apos;';
    break;
    
    }
  }
  str= x.join("");
  
  return str;
}

convertHTML("Dolce & Gabbana");

/*for (var i = 0; i < temp.length; i++) {
        switch (temp[i]) {
          case '<':
            temp[i] = '&lt;';
            break;
          case '&':
            temp[i] = '&amp;';
            break;
          case '>':
            temp[i] = '&gt;';
            break;
          case '"':
            temp[i] = '&quot;';
            break;
          case "'":
            temp[i] = "&apos;";
            break;
        }
      }

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

    //test here
    convertHTML("Dolce & Gabbana");*/

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities[/spoiler]

When you’ve copied across the entity codes (eg '&amp;'), you’ve also copied across a non-visible character between the & and the first letter. Either delete and retype them by hand, or copy from somewhere else (Wikipedia for example)

2 Likes