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

**URL:** <https://forums.ankiweb.net/t/how-to-put-a-random-field-inside-a-div-with-a-script/21508>\
**Category:** Card Design\
**Created:** [July 16, 2022, 2:33pm UTC](https://forums.ankiweb.net/t/how-to-put-a-random-field-inside-a-div-with-a-script/21508 "2022-07-16T14:33:02Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![kleinerpirat](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/kleinerpirat/32/19863_2.png) [@kleinerpirat](https://forums.ankiweb.net/u/kleinerpirat)\
**Post date:** [July 16, 2022, 5:33pm UTC](https://forums.ankiweb.net/t/how-to-put-a-random-field-inside-a-div-with-a-script/21508/9 "2022-07-16T17:33:13Z")

</div>

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:

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

```

---

_[View the full topic](https://forums.ankiweb.net/t/how-to-put-a-random-field-inside-a-div-with-a-script/21508)._
