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
letandconstin the first two lines withvar - Wrap the whole code in curly braces (or in IIFE) to prevent polluting the global namespace