Using Button pressCount to countdown # of attempts left

Adding this becasue I searched for an example and couldn’t find one and took some experimenting to get right. Hopefully it helps someone else!

I have an activity where students get 30 attempts to submit a coordinate point on a table.

All of this goes in the CL for the button component.

To limit number of submits:

                disabled: this.pressCount=30

To display the countdown on the button:

                label: " (${numericValue("${30}-${this.pressCount}")} attempts left)"

Obviously change the "30"s to match how many attempts you want students to have.

I also changed the button color so it will turn red when they get close to running out of attempts:

                 style:
                        when this.pressCount >= 25 buttonStyles.red
                        otherwise buttonStyles.default
2 Likes

I’ve used this to check tables as well. Just a few pointers.

  1. You could make a variable:
    p=this.pressCount
    This way you can just use “p” in the multiple places you use “this.pressCount”. (You could also make a variable for the 30 in case you wanted to just change the max in one place in your code.

  2. You only need to put variables in ${ }, so i’s not necessary for the 30 in your numericValue.

Thanks, I appreciate the shortcuts. I’m still newish to CL, so I know my code isn’t as succinct as it could be.

Just trying to pass on the tips and tricks I’ve learned here along the way.