Tell us what’s happening:
My solution passes all tests, but I don’t understand str = str.replace(/^['"]/,"");
.
Why does this line remove both beginning and ending "
or '
?
The output of 'Stuff in "quotation marks"'.replace(/^['"]/,"")
is Stuff in "quotation marks"
My original solution to remove beginning and ending quotes once is str.replace(/^['"]/,"").replace(/['"]$/,"")
Your code so far
Summary
This text will be hidden
function convertHTML(str) {
const html = {
"&": "&",
"<": "<",
">": ">",
"\"": """,
"'": "'"
};
str = str.replace(/^['"]/,"");
console.log(str);
for (let char in html) {
let regex = new RegExp(char,"g");
str = str.replace(regex, html[char]);
}
return str;
}
console.log(convertHTML("Schindler's List"));
// convertHTML("Dolce & Gabbana");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Convert HTML Entities
Link to the challenge: