Convert HTML Entities - console.log shows correct, answer won't be accepted

Tell us what’s happening:
The console.log test in the end, proves that the code if working correctly. But when I run it, it fails on those exact two tests:

  • convertHTML('Stuff in "quotation marks"') should return Stuff in &​quot;quotation marks&​quot; .
  • convertHTML("Schindler's List") should return Schindler&​apos;s List .

Is there a bug in this challenge?
Thank you for your help!

Your code so far

function convertHTML(str) {
  let newStr = "";

  function monaPaTaka (input) {
    let splitStr = input.split("");
    for (let j = 0; j < splitStr.length; j++) {
      if (splitStr[j] === "&") {
        splitStr[j] = "&amp;";
      if (splitStr[j] === "<") {
        splitStr[j] = "&lt;";
      if (splitStr[j] === ">") {
        splitStr[j] = "&gt;";
      if (splitStr[j] === '"') {
        splitStr[j] = '&​quot;';
      if (splitStr[j] === "'") {
        splitStr[j] = "&​apos;";
    newStr = splitStr.join("");

  return newStr;

convertHTML('Stuff in "quotation marks"');
convertHTML("Schindler's List");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36.

Link to the challenge:

Sort of. The code you’ve written isn’t correct. Delete the entity codes and replace them either with ones copied from somewhere like Wikipedia, or write them by hand.

At the minute there is a hidden character between the & and the next character. This is present in the example so if you’ve copied and pasted from there you’ve copied and pasted something that won’t work.

1 Like

Thank you so much! I’ve rewritten them by hand and now it works.

1 Like