Define variable in reference to another variable

I am working in a button component and the bolded portion of the code below displays the error “Unexpected token $”. I am not sure how to format the idea I have. I want to this code to be reusable in future slides, where all I have to do is set the number of attempts and then the rest of the code is generalized to work in reference to that variable.

How do I format it so that the button changes to red on their last attempt?

#Set number of attempts students get

#Disables button after certain number of attempts
disabled: this.pressCount=attempts

#Displays number of attempts remaining
label: " ({numericValue("{attempts}-${this.pressCount}“)} attempts left)”

#changes color of button after certain number of attempts
when this.pressCount >= ${attempts}-1
otherwise buttonStyles.default

You only need to wrap the variable in ${…} when you’re inside of quotes or backticks. So you can just reference attempts like when this.pressCount > attempts ...

However I don’t think you can do calculations like subtract one in CL, so attempts - 1 won’t work I don’t think. So you’d either need to use




to get what you require.

1 Like