Going to Random Screens


I have a student who is building his multiple screen app. He wants the app to randomly go to different screens as he clicks on his buttons. Is there a way to do this?


I don’t think he can program the app to randomly go to different screens as he clicks on his buttons. In stage 5, if-statements are first introduced but are really addressed in Stages 7 & 8. If-statements are conditional statements that tells the computer to run specific code if something is true. Adding if-statements into the event handler, is one way to switch screens when the condition is true. This isn’t random though.



He will have the blocks he needs by Stage 5. He needs a variable to store the random number and conditionals to make a decision based on the value of that variable. Depending on the student and my plans for the class, I might tell the student to save his idea for later or let him figure it out now. I have a student whose Stage 3 clicker game met all the requirements of the Stage 5 project. I challenge him to provide and receive peer feedback and to be able to communicate his process.



There’s a technique we use in lesson 10 for randomly choosing an element id. So you can look at that lesson. But the short version is:

  1. Give the ids of the screens a consistent naming scheme that has a number in it. i.e. “screen1”, “screen2”, “screen3” and so on.

  2. When you want to generate a random screen id, make a string that tacks a number onto “screen”. Like so:

"screen" + randomNumber(1,5)

In code it might look like this:



thanks @baker even better than nesting if then else…



Thanks to all for your suggestions!
We ended up typing in some code ourselves and used this:

We are allowing our students to use App Lab for 5.3 as they were wanting to do more than what was available in the 5.3 code. They are having so much fun with this!