I am quite close to solving the Convert HTML Entities challenge, but I have some trouble with the replacements of the quotation marks. As you can see, I have inserted the HTML symbols to be inserted in an object.
Problem is, I cannot get the quotation marks to work properly. convertHTML('Stuff in "quotation marks"')
should return "Stuff in "quotation marks""
. But in my case it is not replacing anything, and just returning the same exact sentence back (‘Stuff in “quotation marks”’.)
Will I have to abandon this approach, or is there a way to get the quotation marks to be replaced with "
Your code so far
function convertHTML(str) {
let replacements = {
"&": "&",
"<": "<",
">": ">",
'""': """,//THIS PROBLEM ME MUCH
"'": "'",
"<>": "<>",
}
return str.replace(/(&|<|>|""|'|<>)/gi, function(noe) {
return replacements[noe];
});
}
convertHTML("Dolce & Gabbana");
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
.
Challenge: Convert HTML Entities
Link to the challenge: