202306-NEA-DZ-FEW/madlibs-de-coded

update Preview: cannot modify the function to receive an array as an argument:

Closed this issue · 1 comments

in the function Update Preview

function updatePreview() {
  while (madLibsPreview.firstChild) {
    madLibsPreview.removeChild(madLibsPreview.firstChild);
  }

  temp.forEach((word) => {
   
    if (word.pos) {
      const input = madLibsEdit.querySelector(`input[data-index="${temp.indexOf(word)}"]`);
      const span = createSpan(input.value);
      madLibsPreview.appendChild(span);
    } else {
      const span = createSpan(word.word);
      madLibsPreview.appendChild(span);
    }
  });
}

I want the function to take an array as a parameter. and change temp.forEach to: array.forEach so I can call the function with an array as an argument to update the preview based on that array. but I am gertting: Uncaught TypeError: array.forEach is not a function at HTMLInputElement.updatePreview

the issue was with the eventListener in the createInput function
before: input.addEventListener("input",updatePreview);
now: input.addEventListener("input", () => updatePreview(processedStory));

problem solved