Show/Hide a Component

I thought this was a useful technique to share. Show/hide a component with one button.

In the button CL:

label:
when numericValue("(-1)^{${this.pressCount}}") = 1 “Show”
otherwise “Hide”

In the component you want to show/hide:

hidden: numericValue("(-1)^{${showHide.pressCount}}")=(1)

make sure to name your button showHide
this starts off with component hidden and will show it. If you want to start with it shown and then hide it, use the following:

In the button CL:

label:
when numericValue("(-1)^{${this.pressCount}}") = 1 “Hide”
otherwise “Show”

In the component you want to show/hide:

hidden: numericValue("(-1)^{${showHide.pressCount}}")=(-1)

4 Likes

Nice! I use mod to toggle stuff like this:

p=hint1.pressCount
hidden: numericValue("\mod(${p},2)")=0

The other nice thing with mod is you can have more than a binary on/off toggle. I have some activities were I might have something “toggle” mod 4 or 5 or whatever, to cycle through several states and then start over.

2 Likes

awesome I have never used mod before, please explain

It’s basically a division and the output is the remainder. So, anything mod 2, even numbers output 0, odd output 1.

2 Likes

negatives work the same?

Negatives work in the mod function. You can play around with the mod function in the graphing calculator to get a feel for how it works:

1 Like

got it thanks. I just created a self checking for myself to figure it out

1 Like