Let instruction within a function

So new to this and posted some code in another thread - its’ been pointed out to me functions would save some repeats in my coding and make them easier to read and correct.
But I’m missing a subtly - the let instruction within my function results in this error - yet the same instruction (commented out in the screenshot) seems to work just fine - what am I not grasping?

The problem is not with your let statement. The problem is that you use the await keyword in your function, but the function has not been declared as an asynchronous function. The fix is to put the keyword “async” in front of your “function” keyword in line 10. You also need the “await” keyword where you call the function on line 7.

By the way, the squiggly red underline in line 4 is unrelated to the error you are seeing. That is the linter warning you that the record could potentially be blank, which could result in an error at runtime.

1 Like

Thankyou - that gets it running but why does the let statement oiutside the function work but that inside not - it shows the buttons but their is no pause to wiat for a click - the script just ends

You didn’t add the additional await keyword that I told you to include in line 7 (now line 8).

As for why you are seeing the behavior you are seeing–that requires a deeper understanding of how asynchronous code and promises work. However, since you currently have a large learning curve in front of you, this is a concept that you can delay learning until later, as long as you remember to always use async and await in conjunction with each other.


This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.