# Issues with Scripting in Cards

**URL:** <https://forums.ankiweb.net/t/issues-with-scripting-in-cards/33054>\
**Category:** Help\
**Created:** [August 11, 2023, 12:27am UTC](https://forums.ankiweb.net/t/issues-with-scripting-in-cards/33054 "2023-08-11T00:27:14Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![NielegalneApfelschor](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@NielegalneApfelschor](https://forums.ankiweb.net/u/NielegalneApfelschor)\
**Post date:** [August 11, 2023, 9:15am UTC](https://forums.ankiweb.net/t/issues-with-scripting-in-cards/33054/2 "2023-08-11T09:15:31Z")

</div>

Try enclosing your script in a function, like this:

> [@Card template javascript variables carrying over to next card](https://forums.ankiweb.net/t/card-template-javascript-variables-carrying-over-to-next-card/33040/2):
>
> The easiest way is to enclose your whole code in a function, like this: \<script\> function stuff(){ // your code here ... } stuff() // or with an anonymous function: (()=\>{ // your code here ... })() \</script\> You can also avoid the error by using var instead of const or let.

---

_[View the full topic](https://forums.ankiweb.net/t/issues-with-scripting-in-cards/33054)._
