Implement an HTML Entity Converter - Implement an HTML Entity Converter

Tell us what’s happening:

I don’t understand why it doesn’t pass the test..

Your code so far

const convertHTML=(string)=>{
  const newString='';
  for(let i=0; i<string.length; i++){
    let oneSymbol = string[i];
    if(string[i]==='&'){
      oneSymbol='&amp';            
    } else if(string[i]==='<'){
      oneSymbol='&lt'; 
    } else if(string[i]==='>'){
      oneSymbol='&gt'; 
    } else if(string[i]==='"'){
      oneSymbol='&quot'; 
    } else if(string[i]==="'"){
      oneSymbol='&apos'; 
    } 
     newString+=oneSymbol;
  }
  return newString;
}

Your browser information:

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

Challenge Information:

Implement an HTML Entity Converter - Implement an HTML Entity Converter

have you tried to call your function to test? console.log(convertHTML("Dolce & Gabbana"))

Yes, everything displays correctly in other editors. Nothing changes in the site console.

so you are not seeing this?

TypeError: "newString" is read-only

I already changed const; for some reason, the old version was sent. The other editors show everything is done correctly, and so does the AI.

I can only check the code you post

You need to check carefully the code for html entities

don’t trust the AI, it is often not right

const convertHTML=(string)=>{
  let newString='';
  for(let i=0; i<string.length; i++){
    let oneSymbol = string[i];
    if(string[i]==='&'){
      oneSymbol='&amp';            
    } else if(string[i]==='<'){
      oneSymbol='&lt'; 
    } else if(string[i]==='>'){
      oneSymbol='&gt'; 
    } else if(string[i]==='"'){
      oneSymbol='&quot'; 
    } else if(string[i]==="'"){
      oneSymbol='&apos'; 
    } 
     newString+=oneSymbol;
  }
  return newString;
}
``` here is my code.

you need to look at the html entities code, like I said before

Hi @ryslann95

Check how many characters are in the HTML character code, and how many characters are in your loop for the oneSymbol assignment.

Happy coding

Got it, I missed the semicolon). Thx

1 Like