Game: Conditionals

Student would like to have the game run if the right answer is clicked to have confetti to fall from the top of the screen and if the wrong answer is clicked, the snake to pop up and say game over.

Hello! Looks like your student has figured out how to make the confetti fall, but just not how to make it start falling when they want to.

Here’s a little bit of “pseudo-code” . for you. How about suggesting that they initially set the confetti y value to a negative number (above the screen). Then, maybe create a variable called “falling” that has a value of 0 (or false) to start with. Then, when the mouse is clicked, the “falling variable” could be made true and a conditional could say if falling is true, the y value of the confetti could be augmented (like they are already doing).

Then, for the snake, they could initially position the snake where they want it and at the size they want it, but set the visibility to 0 (snake_1.visibility=0;). Then, when clicked, the visibility would be changed to true (1).

Does this help? Let us know if they still run into difficulties.

Mike

1 Like

Thanks so much! This helped the student quite a bit. The last piece is that the student is stuck on getting the confetti to fall from the top of the screen down to the bottom when the right answer is clicked just once…

Yes, I can see they’ve made progress. A few things. Right now, it requires a mouse click to just move the confetti 1 pixel. If they were to create a switch that is activated when the mouse is clicked and make that the condition for the confetti y value to change, it would continually add 1 to the y value and the confetti would continually fall.

Think about creating a variable at the very beginning of the program such as var switch = false;

Then, when the mouse is clicked, change the switch to true and then have the switch being on be what triggers the confetti falling. That way, when the mouse is clicked once, the conditional will be true and will continually activate.

Hope that makes sense! Best of luck!

Mike