This convoluted solution seems to work in Atom.
Why it doesn’t pass the challenge?
function convertHTML(str) {
let newStr = '';
let regex = /&/g;
let regex1 = /</g;
let regex2 = />/g;
let regex3 = /"/g;
let regex4 = /'/g;
let regex5 = /&|<|>|'|"/g;
if (str.search(regex5)) {
newStr = str;
}
let replaceEntities = entitie => {
if (entitie === '&') {
newStr = str.replace(regex, '&mp')
} else if (entitie === '<') {
newStr = str.replace(regex1, '<')
} else if (entitie === '>') {
newStr = str.replace(regex2, '>')
} else if (entitie === '"') {
newStr = str.replace(regex3, '"')
} else if (entitie === "'") {
newStr = str.replace(regex4, ''')
}
}
for (var i = 0; i < str.length; i++) {
replaceEntities(str[i])
}
return newStr;
}
convertHTML('Stuff in "quotation marks"');
Your browser information:
User Agent is: Chrome.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities/