Implement an HTML Entity Converter - Implement an HTML Entity Converter

Tell us what’s happening:

I am showing as passed but its not giving the correct result that is needed from the lab.
Specifically its showing the & < > and not the HTML characters

Your code so far

function convertHTML(str){
  let result = "";
  const specialHTML = {
    "&":  "&amp;",
    "<":  "&lt;",
    ">":  "&gt;",
    '"':  "&quot;",
    "'":  "&apos;"
  };

  for (let i = 0; i < str.length; i++) {
    let index = str[i];
    let replace = "";
    
    if(specialHTML[index]){
      replace = specialHTML[index]
      result += replace;

    } else {  
      result += index;
    }
  };

  return result;  
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36

Challenge Information:

Implement an HTML Entity Converter - Implement an HTML Entity Converter

Hi @toothpick164 ,

Test you function like this:

console.log(convertHTML("Dolce & Gabbana")); 
console.log(convertHTML('Stuff in "quotation marks"'));

Then look at the result in your browser’s console, not the fCC console.

Happy coding!