Help

Let instruction within a function

Topic Labels: Extensions
Solved
Jump to Solution
692 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Neil_Thorman
6 - Interface Innovator
6 - Interface Innovator

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?

Screenshot 2022-02-02 at 14.12.53

1 Solution

Accepted Solutions

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.

See Solution in Thread

3 Replies 3

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.

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

Screenshot 2022-02-02 at 14.32.12

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.