Convert HTML Entities (Function in Replace)

Tell us what’s happening:
the answer seems correct with console.log()
can someone tell me whats wrong?

Your code so far


function convertHTML(str) {
  // :)
  return str.replace(/[&<>"']/g,function(m,o,s){
    
    switch(m){
      case "&":
      return "&​amp;"
      break;
      case "<":
      return "&​lt;"
      break;
      case ">":
      return "&​gt;"
      break;
      case "\"":
      return "&​quot;"
      break;
      case "\'":
      return "&​apos;"
      break;
    }
  });
}
console.log(convertHTML("<>"))
console.log(convertHTML("Dolce & Gabbana"))
console.log(convertHTML("Hamburgers < Pizza < Tacos"))
console.log(convertHTML("Sixty > twelve"))
console.log(convertHTML('Stuff in "quotation marks"'))
console.log(convertHTML("Schindler's List"))
convertHTML("<>")
convertHTML("Dolce & Gabbana");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities

Look this:

1 Like