Higher or Lower Game - Go Button Introduction

Опубликовано: 31 Июль 2026
на канале: Educational Bytes
4,960
like

An instructional video showing how to set up a basic guessing game where the user guesses whether the next random number will be higher or lower than the current random number. The app was created within MIT App Inventor 2 for Android. This is the third video for the Higher or Lower Game, and is intended to help set up the Go Button event if you could not get started on your own. The video is used as part of lab for University of California, Riverside's CS 005 course and thus mentions a few things related to "a lab." The algorithm for the "Go" button has been extracted from the lab specification and listed below.

Go Button Algorithm:
1. Create a variable to store what will become to old random number.

2. Store the current value of the random number in the variable that you created.

3. Generate a new random number between 1 and 100, storing it into the variable randomNum. Also, update the label that displays the random number.

4. Using control blocks, determine if the user pressed the higher button.

a) then (if higher was tapped)
Output "You guessed correctly" if the new number is higher than the old number and add one to the streak number. Otherwise output "Sorry, you were wrong :(" and reset the streak number to 0. In each case also set the text color, use green if the user was correct and red if the user was incorrect.

b) otherwise (if higher wasn't tapped)
Output "You guessed correctly" if the new number is lower than the old number and add one to the streak number. Otherwise output "Sorry, you were wrong :(" and reset the streak number to 0. In each case also set the text color, use green if the user was correct and red if the user was incorrect.

5) Clean up the game, resetting the values for the next turn; similar to initializing the game. All component text values and colors are updated to the initial values you can see in the designer (except StreakNumber). Remember to disable the Go button.