Convert HTML Entities not passing test

Convert HTML Entities not passing test
0

#1

Tell us what’s happening:

Only the last test is passing. everything else appears to be returning the correct result … I cant understand why this is not being accepted…

Your code so far


function convertHTML(str) {
  
  if(str.match(/&/)){
      str = str.replace(/&/, "&​amp;")
  };

  if(str.match(/>/)){
     str = str.replace(/>/, "&​gt;")
  }

  if(str.match(/</g)){
     str = str.replace(/</g, "&​lt;")
  }

  if(str.match(/"/)){
     str = str.replace(/"/, "&​quot;")
  }
  
  if(str.match(/'/)){
     str = str.replace(/'/, "&​apos;")
  }

  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/


#2

If you copied/pasted the replacement html values, then they probably have hidden characters which are throwing off the tests. Try manually typing out each replacement string and I bet you pass the challenge.


#3

Wahey, yeah it does ! thanks for that :slight_smile: