Guess the Number Game - Individual Scratch Blocks
First, create these variables:
secret number (for all sprites)
guesses (for all sprites)
guess (for all sprites)
Stage Blocks:
[image: When green flag clicked] open
[image: Hide] open
[image: Delete all of [guesses]] open
[image: Set [secret number] to] open
[image: pick random (1) to (100)] open
[image: Say [Let's play! Guess a number between 1 and 100.] for (2) seconds] open
[image: Show] open
Cat Sprite Blocks (Main Game Logic):
[image: When green flag clicked] open
[image: Set [guesses] to (0)] open
[image: Forever] open
[image: Ask [Enter your guess:] and wait] open
[image: Set [guess] to (answer)] open
[image: Change [guesses] by (1)] open
[image: If <> then] open
[image: <(guess) = (secret number)>] open
[image: Say [Correct! The number was] for (4) seconds] open
[image: Join [Correct! The number was ] [(secret number)]] open
[image: Join [. You won in ] [(guesses)]] open
![Join [] [guesses!]
[image: Stop [this script]] open
[image: Else] open
[image: If <> then] open
[image: <(guess) > (secret number)>] open
[image: Say [Too high! Try again.] for (2) seconds] open
[image: Else] open
[image: Say [Too low! Try again.] for (2) seconds] open
Step-by-Step Instructions:
- Open Scratch and create a new project
- Create the three variables:
secret number, guesses, and guess
- Stack the blocks for the Stage as shown above
- Stack the blocks for the Cat sprite as shown above
- Click the green flag to play!
When the player runs the game, it will:
- Generate a random number between 1-100
- Ask players to guess the number
- Give "too high" or "too low" feedback
- Count the number of guesses
- Congratulate the player when they guess correctly
Would you like me to explain how any specific part works?