Convert html entits

Tell us what’s happening:
help please this two didnt pass test…
convertHTML('Stuff in "quotation marks"') should return "Stuff in "quotation marks"" .

convertHTML("<>") should return "&lt;&gt;" .

Your code so far


function convertHTML(str) {


for(let string of str){
     
  switch(string){
case '&':
 return str.replace(/&/g,"&amp;")
 break;
case '<':
 return str.replace(/</g,"&lt;")
 break;
case '>':
 return str.replace(/>/g,'&gt;')
   break;
case "":
 //return str.split(s[i]).join('&quot;')
 return str.replace(/""/g,'&quot;')
 break;
case "'":
 //str.split(s[i]).join('&apos;')
  return str.replace(/'/g,'&apos;')
break;


  }
  
     }
  
  
return str
}

convertHTML("Hamburgers < Pizza < Tacos");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; rv:80.0) Gecko/20100101 Firefox/80.0.

Challenge: Convert HTML Entities

Link to the challenge:

this is an empty string
to have a double quote here you can write '"' or "\""

second issue: a return statement stops the function, so after the first symbol is met, others are not changed

2 Likes