Tell us what’s happening:
Hello, I’m not sure why my code is not passing all of the tests. It fails the second, fourth, and sixth test, but it passes the rest of the tests. I am aware that there is a bug regarding zero-width characters and I have already removed them (via JSFiddle).
Your code so far
function convertHTML(str) {
let regex = /[&<>"']/gi;
let char = str.match(regex);
if (char == "&") {
str = str.replace(regex, "&");
}
else if (char == "<") {
str = str.replace(regex, "<");
}
else if (char == ">") {
str = str.replace(regex, ">");
}
else if (char == '"') {
str = str.replace(regex, """)
}
else {
str = str.replace(regex, "'")
}
console.log(char);
console.log(str);
return str;
}
convertHTML(">");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
.
Link to the challenge: