Convert HTML Entities challenge

Hello, I tried to come up with a simple solution to the challenge by using a switch case, which turns out to be not so simple.

Here’s what I have at the moment:

function convertHTML(str) {
  // :)
  var words = str.split("");
  return words.map( word => {
  switch(word) {
      case "&":
      return "&​amp;";
      break;
      case "<":
      return "&​lt;";
      break;
      case ">":
      return "&​gt;";
      break;
      case "<":
      return "&​lt;";
      break;
      case "\"":
      return "&​quot;";
      break;
      case "'":
      return "&​apos;";
      break;
      default:
      return word;
      }
  }).join("");
}

convertHTML("Dolce & Gabbana");
console.log(convertHTML("Dolce & Gabbana"));
console.log(convertHTML("Hamburgers < Pizza < Tacos"));</code>

The output are:

Dolce &​amp; Gabbana
Hamburgers &​lt; Pizza &​lt; Tacos

which seems to be correct to me? So I’m stuck wondering where went wrong…any ideas why? Thanks!

The case where you say case """ shouldn’t be correct. You should scape the quote: case "\"".

And are you using this quotes “ or this ones "?

Formatting the code made my comment completely useless. Lol

1 Like

Yes, that solved it. The hidden characters made the tests not passing, I simply copy and paste back which solved the issue. Thanks alot!