Pair Programming in Scratch Create a Number Guessing Game

How to Create a Number Guessing Game in Scratch: Pair Programming

By Team BrightChamps
Home » Code for Kids Corner » How to Create a Number Guessing Game in Scratch: Pair Programming

Anyone who is into coding must be aware of what Scratch is.

It is a platform and a block-based visual programming language that has made coding easy for kids and beginners ever since its inception.

Coders can create various Scratch projects, and scratch games can be developed.

In this blog, we will talk about one of the many interesting games kids can make in Scratch, a number guessing game.

How to Create a Number Guessing game in Scratch

This game is created with an interesting programming technique called Pair programming.

In Pair programming, two coders collaborate from a single workstation, one as the Driver and the other as the Navigator.

The driver will be responsible for the computer’s primary functions, i.e. they’ll write codes. 

The navigator assists the driver by answering questions and pointing out any problems or errors.

Communication is the key to having successful pair programming. 

The navigator should think and brainstorm ideas while the driver works on the project.

Be courteous to the driver and thoroughly explain everything to him or her—every 10 minutes, switch roles.

Steps to create a Number Guessing Game in Scratch

Make sure that you are a registered Scratch user and that you are signed in before you click on the create button on Scratch.

How to Create a Number Guessing Game in Scratch_ Pair Programming Step 1

Step 1: 

The navigator will instruct the driver to use one sprite (who will tell the user what to do and whether or not their guess is correct) and two variables (number and guess). The majority of our code is stored in the Sprite.

We need the computer to pick a number and remember it before we ask the user for their guess/answer.

So we require a variable for the computer to remember a value or number. A variable is a location on the computer where values can be stored.

FIRST: Coding in the SPRITE, take a block from Events called ‘when the green flag is clicked,’ then create a variable called the number, and get the block ‘set the number to 0’.

Attach the ‘pick a random number’ block from the Operators to the variable: number (choose any random number between given numbers to guess).

Then, from the Looks, take the ‘say’ block, type in the message that you are thinking of a number between 1 and 100 and have a few guesses to find it.

SECOND: Once the driver has entered the aforementioned commands, the driver, and navigator can check the provided code and proceed to step 2.

How to Create a Number Guessing Game in Scratch_ Pair Programming Step 2

Step 2: 

Following step 1, the driver can obtain the ‘ask’ block from Sensing (users can answer their guess in the variable from the stage screen), followed by the ‘set guess variable to 0’ block from Variables.

Next, insert the ‘answer’ block into the variable as shown. 

NOTE: When you use the ‘ask’ command, the user input (their guess) is always stored in the variable ‘answer’ until you re-assign it to your variable ‘guess’ in data using the ‘set variable’ command. The driver and navigator can discuss the variables or switch roles and move forward to Step 3.

How to Create a Number Guessing Game in Scratch_ Pair Programming Step 3

Step 3: 

The navigator can explain the next commands to the driver and code them accordingly.

When you want to test something, use the ‘If Then’ block. You can use the green operator’s tab and select the greater than (>) operator to see if the number is greater than our variable. 

Place the blue ‘answer’ block on the left side of the green ‘>’ block, and place the orange variable on the right side of the block.

The driver can put any code inside the ‘if-then block’ to test if the user’s answer is greater (>) than the selected number. 

You can investigate the case where the user selects a number from the operators that is less (<) than the number selected by the device.

The equals sign (=) can then be used if the user selects the same number that the device or computer did.

How to Create a Number Guessing Game in Scratch_ Pair Programming Step 4

As shown in the picture, after adding a comparison with the operators to a specific ‘if-then‘ block, the guess and number variables are compared, and to execute the ‘if-then’ block, add a ‘say’ block from Looks.

Step 4: 

The final step is to loop by adding a ‘repeat’ block from Looks.

Attach the ‘repeat’ command above the ‘ask’ command to keep giving the user chances to get it right. The driver and navigator can switch roles to check the game and get the correct response.

Last, attach the ‘say’ block from Looks to the ‘repeat’ block to display the guesses after the attempts. To connect the sentence and the variable number, use Operators’ ‘join’ block.

In such a case, the probability of guessing the number will be displayed.

How to Create a Number Guessing Game in Scratch_ Pair Programming Step 5

If you would like to know more about free coding games for kids. Checkout here!

Conclusion

If a user responds appropriately, you can change the game’s background to make it more engaging. To make the game more interesting, the players might also receive prizes for accurately guessing the number.

It might be an applauding noise or a piece of artwork. Depending on your creative vision, you can incorporate many more of these components.

Once the project is completed, the driver and navigator can have a round to see who wins the game. It will make the whole process more enjoyable. Check out the most recent entertaining blogs on the Brightchamps blog page to find out more about pair programming and other entertaining Scratch features.

BrightChamps provides financial education for kids, equipping them with essential money management knowledge for a successful future.

Frequently Asked Questions (FAQs)

What is the point of the Number Guessing Game in Scratch? 

The goal is to guess the number generated by the program. The program selects a number between 1 and 100 at random. It will then ask the player to enter their guess through a series of turns.

What are the rules for guessing numbers in the Scratch project? 

If the user cannot guess anything other than a number, they are eliminated. Every time the user makes a guess, the thinker must (honestly) respond with one of three options: your guess is too high, your guess is too low, or your guess is correct. The user wins if the number is correct.

What are the possibilities of winning the game in Scratch? 

After a few attempts, the user can play the game by guessing the answer based on the high and low areas. The user can try to set a limit to check the range in high and low and try out different options.

Team BrightChamps

We are an army of educators and passionate learners from BrightChamps family, committed to providing free learning resources to kids, parents & students. Learn from Us

Reach Us

Categories

General Sidebar Widget Coding

Get a Talent Discovery Certificate after trial class

100% Risk-Free. No Credit Card Required

Related Articles

Trending Articles