Guess a Number

Assignment 3:  Guess a Number

Make a Scratch project that engages the user in a number guessing game.

Your game will follow these steps.  You can get creative and add to this, but this is the simplest way to complete the assignment:

  1. Introduce the game
  2. Secretly pick a random number from 1 to 10
  3. Keep asking the user to guess a number until they get it right.  For each guess, tell them if it is too high or too low.
  4. After they guess it correctly, congratulate them and tell them the correct answer.

There is a video which introduces this assignment and quickly describes the blocks required to complete it.  There are two videos supporting this assignment:  a video explaining the concepts applied, and a second video showing a complete example of the assignment.

This assignment applies the concepts of conditional processing, string concatenation, and Boolean expressions.  These concepts including their use in Scratch programs is addressed in the video and will be on the quiz.

Minimum Requirements

Create a variable and set its value to a random number from 1 to 10.

Introduce the game with at least one “say” block(s).

Use a “repeat until” block to keep asking for guesses until the correct answer is guessed.  This is an iterative loop with a Boolean expression controlling how many iterations occur.

Provide feedback on guesses.  At a minimum, tell the user if their guess is too low or too high.  This applies Boolean expressions with conditional processing:  something different happens depending on whether a condition is true.

When the correct number is guessed, congratulate the user and tell them in one “say” block, “the number was 4” or whatever the number was.  You need to use a “join” block to put the words together with the variable where the answer is stored.  The join block implements string concatenation, one of your vocabulary terms which will be on the quiz.

Your project must have at least one sprite, a non-white stage backdrop, one sound effect, and start when the green flag is clicked.

Your project, sprites, and variables must all have meaningful and descriptive names.

New blocks you will need to use:

Variables Create a variable to keep track of the chosen number the user is trying to guess
Sensing / Ask Collect information from the user.  Ask them to guess a number from 1 to 10
Sensing / Answer A special predefined variable which is set to the answer to the question most recently asked.

Each time “ask” is used, the value of “answer” is set to whatever the user typed.

Control / Repeat Until Wraps a sequence of blocks that will repeat in an iterative loop until the “repeat until” Boolean expression is true.  Keep asking the user to guess and telling them if they are too high or too low until their answer equals the chosen number.
Operators / Join Join variables or calculated values together with text to form a sentence.  For example “The number was 7” where 7 is the randomly selected value, which can change each time the program runs.  This is an implementation of string concatenation
Operators / Pick Random  Like rolling dice, but you choose the range of values.  The computer will pick one at random.
Operators / Comparisons: = , >, < Boolean expressions to compare two values.  These will always be true or false.  5 = 5 is true.  5 > 6 is false. 6 < 7 is true.  Typically goes inside a control block such as “if” and “repeat until”.  For example, “repeat until the user’s answer = the chosen number”

That’s a lot of blocks!  Take your time and experiment with each one to get comfortable with how it works.

You can unsnap a handful of blocks and just double-click them to quickly try something out.

Exceeding Expectations

Is this too easy?  Are you some kind of Scratch guru?  Here are some extra features for those who seek to exceed expectations:

Tell them if they are “way too low” or “way too high” if their guess is more than 2 away from the number.

Keep track of how many guesses it takes the user to guess correctly.  This will require a new variable, which will need to be updated each time the user makes a guess.  At the end, tell them “It took you ___ guesses.” where you use multiple “join” blocks to put the words together with the number of guesses.

Keep track of high scores and make a high score list.

Turn this into a “guess the item from the list” game.  For example, guess the color of the rainbow, guess the football team, guess the flavor of ice cream, etc.  Store the values in a “list” variable and let the user know what all the values are.  Check to be sure the user typed a value on your list and let them correct their guess to a valid value before telling them if it is right or wrong.