Implement an HTML Entity Converter - Implement an HTML Entity Converter

Tell us what’s happening:

The code is not showing the HTML entities it’s converting them to special characters

Your code so far

function convertHTML(string){
  let array=[["&","&amp;"],["<","&lt;"],[">","&gt;"],['"',"&quot;"],["'","&apos;"]];
  for(let [specialChar,entities] of array){
    console.log(array)
  if(string.indexOf(specialChar)!==-1){
    string=string.split("");
    string.splice(string.indexOf(specialChar),1,entities)
    string=string.join("")
  
    
  }
  }
  return string 
}
console.log(convertHTML("Dolce & Gabbana"))

Your browser information:

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

Challenge Information:

Implement an HTML Entity Converter - Implement an HTML Entity Converter

https://www.freecodecamp.org/learn/full-stack-developer/lab-html-entitiy-converter/implement-an-html-entity-converter

yes, that’s the point of the html entities

you can look at the browser console to see them, or you can use a tool like Online JavaScript Compiler, Visual Debugger, and AI Tutor - Learn JavaScript programming by visualizing code

1 Like