Replace all HTML entities challenge: My solution passes all the test cases but the challenge still doesn't get marked as complete

Replace all HTML entities challenge: My solution passes all the test cases but the challenge still doesn't get marked as complete
0

#1

Hi All

My solution to the Replace HTML entities (intermediate algorithm scripting) passes all the test cases but the challenge doesn’t get completed when I run the code. Any idea what the cause of this could be?
My code:

function convertHTML(str) {
    var entities = {
        '&': 'amp;',
        '<': 'lt;',
        '>': 'gt;',
        '"': 'quot;',
        "'": 'apos;'
    };

    return str.split('').map((e) => {
        return entities[e] || e;
    }).join('');
}

convertHTML("<>")

#2

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#3

The strings in the entities should have the & character in front (like &amp;, &lt;, etc.)