Intermediate Algorithm Scripting - Convert HTML Entities

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**
function convertHTML(str) {
const regex=New regEx(/[&<>'"]/,'g')
switch(char){
case '&':
return '&amp;'
case '<':
return '&lt;'
case '>':
return '&gt;'
case '"':
return '&quot;'
case "'"
return '&apos;'
}
}
return str.replace(regex,convertHTML);
}
convertHTML("Dolce & Gabbana");

  **Your browser information:**

User Agent is: Mozilla/5.0 (Linux; Android 11; SM-A325F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Mobile Safari/537.36

Challenge: Intermediate Algorithm Scripting - Convert HTML Entities

Link to the challenge:

I don’t think you want to return for each case statement. That will cause the function to end immediately and you’ll never do the replace in the last return statement.

You also have typos and an extra closing bracket.

I’d also think you would have to define a replacer function with the switch inside it (you can have the replacer function inside or outside the main function).

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