Intermediate Algorithm Scripting - Convert HTML Entities

Tell us what’s happening:
so i was struggling with this for longer than i wanna admit…
then i go for a hint… end up looking at the first solution… and what i see ends up TO ME and MY noob self like almost the EXACT SAME CODE… plz help
explain whats wrong with MINE… is it the switch statement syntax? am i nestled poorly
Your code so far

function convertHTML(str) {
  let itemArr = str.split("")

  for(let i = 0; i < itemArr.length; i += 1){
    
    //if(itemArr[i]){
// i eventually included this if statement to try to get my switch statement //unignored haha ik thats extra if not wrong i was jus tryyying things by then
    switch(itemArr[i]){
      
      case "<":
       itemArr[i] = "&lt;";
       break;
     
      case " & ":
       itemArr[i] = "&amp;";
    
       break;
     
      case ">":
       itemArr[i] = "&gt;";
       break;
     
      case '"':
       itemArr[i] = "&quot;";
       break;
     
      case "'":
       itemArr[i] =  "&apos;";
       break;
    
    }
//}
  }
 
  return itemArr.join("");
}

console.log(convertHTML("Dolce & Gabbana"))

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36

Challenge: Intermediate Algorithm Scripting - Convert HTML Entities

Link to the challenge:

Did you really mean to have spaces around the ampersand?

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.