Tell us what’s happening:
for the case i have 2 ‘>’ which need replacing it replaces the first one fine but then when i go over the loop again and search it still finds one at charecter 11 so does not find the second or change it, is this something to do with these codes for speical chars does the method read that as the same as > still hence it not updaing?
Your code so far
function convertHTML(str) {
let regex = /[&<>"']/g
let arr = [...str.matchAll(regex)];
for (let i = 0 ; i < arr.length ; i++){
let num = str.search(regex)
switch(str.charAt(num)) {
case '&':
str = str.replace('&', '&')
return str
break;
case '<':
str = str.replace('<', '<')
break;
case '>':
str = str.replace('>', '>')
return str
break;
case '"':
str = str.replace('"', '"')
break;
case "'":
str = str.replace("'", ''')
break;
default:
return str
} }
return str;
}
console.log(convertHTML("Hamburgers < Pizza < Tacos"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0
.
Link to the challenge: