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 word => {
  switch(word) {
      case "&":
      return "&​amp;";
      case "<":
      return "&​lt;";
      case ">":
      return "&​gt;";
      case "<":
      return "&​lt;";
      case "\"":
      return "&​quot;";
      case "'":
      return "&​apos;";
      return word;

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 "?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

Note: Backticks are not single quotes.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


If you copied and pasted the replacement values from somewhere, it is possible that you picked up some extra hidden characters when you pasted them into your code. Try deleting the replacement values and manually typing them just in case you had some hidden characters in there. The FCC tests are not expecting to see any hidden characters, so they could be failing because of them.

1 Like

Formatting the code made my comment completely useless. Lol

1 Like

Yeah, that can happen. Unformatted code make quotes show up as curly quotes.

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!