Convert HTML Entities Intermediate algorithm

Tell us what’s happening:
Unable to pass the tests, though the output is correct.

Your code so far

function convertHTML(str) {

str= str.replace("&","&​amp;");
str= str.replace(/[<]/gi,"&​lt;");
str= str.replace(">","&​gt;");
str= str.replace(/"/gi,"&​quot;");
str= str.replace("'s","&​apos;s");

  return str;
}


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

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.

markdown_Forums

1 Like

Wow. Huh. Tracked back your problem, and it was a doozy to track down.

I actually went back to the intermediate answer, copied theirs, ran the two side by side, saving them into separate strings, and comparing the strings letter by letter.

You have an invisible character following your ampersand in every case. Not sure what you did, but that was the glitch. If you want to see the comparison of the two cases, i have it as a fiddle.

Actually, had I been paying attention, it displays it as a strange character in the jsfiddle editor. sigh.