Convert HTML Entities - Intermediate coding challenge

Tell us what’s happening:
I don’t understand why this code doesn’t pass the test. all console.log() outputs the correct sollution

Your code so far



function convertHTML(str) {
    
    const entities = [['&', '&​amp;'],['<', '&​lt;'],['>', '&​gt;'],['"', '&​quot;'],["'", '&​apos;']];

    const re = new RegExp(entities.map(el => el[0]).join('|'), 'g');

    return str.replace(re, match => {
        const index = entities.findIndex(el => el[0] === match);
        return entities[index][1];
    });

}
  
console.log(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/73.0.3683.86 Safari/537.36.

Link to the challenge:

There are invisible characters inside your html entities, this happen if you copy and paste them instead of typing Them.
Try deleting and retyping them

1 Like

Retyped everything and now all tests pass except for

convertHTML('Stuff in "quotation marks"') should return Stuff in &​quot;quotation marks&​quot; .

Why is that?


function convertHTML(str) {
    
    const entities = [['&', '&amp;'],['<', '&lt;'],['>', '&gt;'],['"', '&qout;'],["'", '&apos;']];

    const re = new RegExp(entities.map(el => el[0]).join('|'), 'g');

    return str.replace(re, match => {
        const index = entities.findIndex(el => el[0] === match);
        return entities[index][1];
    });

}
  
console.log(convertHTML('Stuff in "quotation marks"'));

Check your spelling. 'qout' != 'quot'

1 Like

thank you now everything works! :slightly_smiling_face: