Convert HTML Entities, why a billion undefined?

Tell us what’s happening:
when I console.log the result, I see the result as desired, followed by no spaces with a billion of the word undefined, also separated by no spaces. it looks like

abcundefinedundefinedundefined…etc. for pages.

Your code so far


function convertHTML(str) {
  // :)
  let result = ''; let flag;
  let entitieslist = ['&','<','>','"',"'"]
  let entities = {
    '&': '&amp;',
    '<': '&lt;',
    '>': '&gt;',
    '"': '&quot;',
    "'": '&apos;'
  };
  for (let i = 0; i , str.length; i++) {
    flag = false;
    for (let j = 0; j < entitieslist.length; j++) {
      if (str[i] == entitieslist[j]) {
        result += entities[entitieslist[j]];
        flag = true;
      }
    }
    if (flag == false) {
      result += str[i];
    }
  }
  return result + ' ';
}

console.log(convertHTML("abc"));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities

You have a typo in this line.