Issue with Convert HTML Entities

Tell us what’s happening:
Hi everyone,

So I have used a replace function to return the string and its corresponding HTML entities. I have used the console log to ensure that my output is correct, and i replaced the ‘&’ character first to prevent any issues. However, my code is not passing any of the test cases. Any help would be greatly appreciated!

Your code so far

function convertHTML(str) {

  return str = str.replace(/&/g,'&​amp;').replace(/</g,'&​lt;').replace(/>/g,'&​gt;').replace(/'/g,'&​quot;').replace(/"/g,'&​apos;');


console.log(convertHTML("Hamburger's < Pizza < Tacos"));
// output: Hamburger&​quot;s &​lt; Pizza &​lt; Tacos

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0.

Link to the challenge:

While I try something else, can you try use replace with a string instead of regex? It might be an issue with how the tests work.

Also, I think you should get rid of the str =; I don’t think it’s necessary.

Try retyping the replacement strings. Somehow invisible characters got inserted after the & characters.

The strings for ' and " also are swapped.

1 Like

Did you by chance copy/paste the replacement string (the html codes)? It appears you have some extra “hidden” characters in the replacement string. Try manually typing the replacement strings again for each replace.

Also, you are using the wrong conversions for the last two.

Confirmed it is hidden chars.

Ahhh yes I was lazy and copied the replacement strings from the page itself. the tests pass fine now. Thanks guys

I was just curious how did you guys manage to see and display these hidden characters?

Unlike me, they have more experience, so they are aware of such things happening. So you and I learned something new here, and that is to be wary of copy and pasting!

here you go, just put the suspect strings in here and if you get any red marks, they are the ones causing the trouble