Do javascript for loops work in html templates?

Anki desktop (and maybe AnkiMobile) only updates part of the page when flipping cards, so redeclaring a variable already declared with const or let in the global namespace (i.e. at the top level of the script) will cause an error.

You can try either of the following:

  • Replace let and const in the first two lines with var
  • Wrap the whole code in curly braces (or in IIFE) to prevent polluting the global namespace
3 Likes