Unit 3 Lesson 17 Bubble 6 (?)

Hi:

My student wanted to write some code that had the gift box change to a duck on the 5th click/move toward so that the user would go click, click, click, click, click and then the duck would replace the box.

I was thinking that an IF/THEN statement would work, but didn’t know how to do it:

e.g. If this is the 1st time the user clicked the mouse, then no change.
If this is the 2nd time the user clicked the mouse, then no change.
If this is the 3rd time the user clicked the mouse, then no change.
If this is the 4th time the user clicked the mouse, then no change.
If this is the 5th time the user clicked the mouse, then change to a duck.

How could he do that?

It’s sort of like putting the click instruction in a loop, but then having the loop end after the 5th click.

Does that make sense?

Thank you.

Gary

PS By the way, I “think” it’s bubble 6, but definitely Lesson 17.

What if they created a variable at the beginning of the code such as var clicks=0;

Then, after each click, use the counter pattern to change the value of clicks.

clicks=clicks+1;

Finally, use a conditional (if) statement to check the value of clicks and only change the sprite when clicks = 5.

Hopefully that helps!

Mike

Thank you very much, Mike! I will both of your replies with my students.

Gary

1 Like