How to put a random field inside a div with a script?

The issue is the const keyword. Because the document persists between cards, using const outside of functions (outermost scope) causes a SyntaxError.

Use the keyword var instead or enclose the script in an IIFE, like:

(() => {
  const fields = document.querySelectorAll(".sentence");
  fields[3].hidden = false;
})();
4 Likes