What's wrong with my answer

Tell us what’s happening:
Is there something obvious I am missing? I ran my code in browser console and I got expected result

Your code so far


function convertHTML(str) {
  const arr = str.split('').map((letter) => {
    if (letter === '&') {
      return '&'
    } else if (letter === '<') {
      return '&​lt;'
    } else if (letter === '>') {
      return '&gt;'
    } else if (letter === "\"") {
      return '&​quot;'
    } else if (letter === "\'") {
      return '&​apos;'
    } else {
      return letter
    }
  })
  return arr.join('')
}

convertHTML("Dolce & Gabbana");
console.log(convertHTML("Schindler's List") === 'Schindler&​apos;s List')

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36.

Link to the challenge:

&amp; is fine, but the other return values have a non-breaking space between the & and the first character:

nbsp

When I get to &lt;, the cursor isn’t static there, I’m pressing left and right, it’s just going left and right over an invisible character.

It’s because wherever the entity code has been copied from includes these, it’s a common issue. Delete the character between & and the first letter for each of the values, and the tests will pass.

1 Like