function convertHTML(str) {
// Use Object Lookup to declare as many HTML entities as needed.
// Try to add var before htmlEntities declaration to enable codes passed!
htmlEntities={
'&':'&',
'<':'<',
'>':'>',
'"':'"',
'\'':"'"
};
//Use map function to return a filtered str with all entities changed automatically.
return str.split('').map(entity => htmlEntities[entity] || entity).join('');
}
// test here
convertHTML("Dolce & Gabbana");
Add var before htmlEntities for codes to pass.
var
indeed passes test,. but const
is more accurate.