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.


1 Like

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!



Hi, everyone. I have a question. I have a student trying to do this, but he wants not only that the user goes randomly to any screen, but that the user goes to every one of them.

  • Randomly go to any screen.
  • Make sure that all screens are seen.
  • Make sure that once a screen was visited, does not show up again.
    Help, please.

Does the student want to make this in lesson 3? I don’t think the student has enough skills to build such an app. The best way to do this would incorporate lists (something as shown by @hendricksn above (Going to Random Screens)) . It can be done without lists (using brute force if there are limited number of screens), but the student would need to use conditionals (if-else) which is taught in lessons 7-9.

Thank you so much for your answer. :slightly_smiling_face: