About the Book This coding book is supplementary to the main “Mel n Conji” content book. This book represents a 21st-century approach to learning coding concepts and developing computational thinking and problem-solving skills. To prepare students for the digital age, the curriculum is interwoven with well-thought-out concept graduation with real-life examples and practice problems.
Special Features • Illustrative approach: Concepts in coding and computer science are delivered through pictorial representations and learner-friendly approaches. • Learning through real-life examples: Age-appropriate examples that enable learners to relate to the concept and learn about the unknown from the known. • Extensive practice: Multiple practice scenarios to reinforce learnings. • Coding challenges: Includes projects through which learners can demonstrate their learning outcomes in coding and computer science.
About Uolo Uolo partners with K-12 schools to bring technology-based learning programs. We believe pedagogy and technology must come together to deliver scalable learning experiences that generate measurable outcomes. Uolo is trusted by over 10,000 schools across India, South East Asia, and the Middle East.
Singapore
|
CS_CB_Coding_Grade5_Cover.indd All Pages
Gurugram
|
Bengaluru
|
hello@uolo.com �199
© 2024 Uolo EdTech Pvt. Ltd. All rights reserved.
NEP 2020 based
|
NCF compliant
|
Technology powered
03/12/23 8:02 PM
Computer Science Computer Science
Scratch 3.0 III
CB_Grade 5.indb 1
11/29/2023 1:38:52 PM
CB_Grade 5.indb 2
11/29/2023 1:38:52 PM
Contents 1
Introduction to Scratch 3.0
1
Coding
Scratch 3.0
Starting Scratch 3.0 Adding a Sprite
Duplicating a Sprite Adding Backdrops
2 Control and Sensing Blocks
16
Understanding Control and Sensing Blocks Control Blocks
Sensing Blocks 3 Using Variable and Mathematical Blocks in Scratch
28
Variable and Mathematical Blocks 4 Using Comparison Blocks and Random Blocks in Scratch
42
Comparison Blocks Random Block
iii
CB_Grade 5.indb 3
iii
11/29/2023 1:38:52 PM
CB_Grade 5.indb 4
11/29/2023 1:38:52 PM
Introduction to Scratch 3.0
1 Coding
Coding is the process of creating sets of instructions that a computer can understand and execute. Coding is a way to tell a computer what to do. Coding involves writing specific commands in a programming language to tell a computer how to perform tasks, solve problems, or run applications. Coding is used to develop software, websites, mobile apps, and other digital technologies. Did You Know? Computer programmers sometimes use secret codes to leave messages for each other. It is like having a secret club! They call it ‘Easter eggs’.
Block-based Coding
Block-based coding makes it easier for kids to learn to program because it is like putting together a fun and colourful jigsaw puzzle! Instead of typing complicated words and numbers, you use colourful blocks with pictures on them to create programs. Each block represents a different action or command, and you snap the blocks together like puzzle pieces to make the computer do what you want. Scratch, Tynker, and LightBot are a few examples of block-based coding languages that help us learn and practice our coding skills.
Discuss
Do you and your friends have a secret language that you people talk in? or Codes? Why did you make it and how do you use it?
1
CB_Grade 5.indb 1
11/29/2023 1:38:53 PM
Do It Yourself 1A Fill in the blanks. 1 Coding is used to develop 2 In
,
,
and other digital technologies.
, you use colourful blocks with pictures on them to create programs.
3 Scratch is an example of a
coding language.
Scratch 3.0
Scratch 3.0 is an application program that lets you create your own games, stories, and animations. It is a free platform where you can show your creative skills.
You can make characters move, jump, and talk, and you can even make your own interactive stories or games. Scratch 3.0 is all about using your creativity and imagination to make programs on a computer, and the best part is that you can share your creations with your friends and see what they make too! Creating a story-based Scratch project for solving mathematical expressions is an easy way to learn Scratch 3.0.
Project: Creating Robo Calculator •
Use Scratch’s block-based coding to create interactive math challenges.
•
Use variables to keep track of the Robo Calculator’s progress and scores.
• •
Incorporate sprites and backgrounds to represent characters and settings in the story. Create interactive maths expression solvers where Robo Calculator can input his answers.
2
CB_Grade 5.indb 2
11/29/2023 1:38:54 PM
Did You Know? Scratch was originally developed by the Lifelong Kindergarten Group at the MIT Media Lab to help kids learn to code in a fun and creative way.
Think and Tell What are the other platforms you know of that assist in block-based coding?
Starting Scratch 3.0
Here are the steps to get started with Scratch: 1
Open a web browser like Google Chrome or Microsoft Edge.
2 Go to the Scratch website by typing www.scratch.mit.edu in the address bar and then pressing Enter. 3 Click the Start Creating button on the Scratch website to begin creating your projects.
The Scratch interface appears.
Chapter 1 • Introduction to Scratch 3.0
CB_Grade 5.indb 3
3
11/29/2023 1:38:54 PM
Components of Scratch 9 10 1 2 6 7
3
8
4
5
11
Menu and Title Bar: Here, you will discover menu options for project management and 1 Scratch environment control.
2
Settings
It provides options for Language and Colour Mode settings.
File
It has options like New, Load from your computer, and Save to your computer.
Edit
In the Edit icon, you can enable Turbo Mode, which significantly speeds up the execution of your Scratch project, making your code run faster, which is useful for complex or time-sensitive scripts.
Tabs: Used for switching between Code, Costume, and Sounds, with stage resizing icons.
Block Panel: Contains various categories of coding blocks like Motion, Looks, Sound, etc. 3 for controlling sprite actions, colour-coded for ease. Block Palette: Offers diverse coding blocks; drag and drop to create scripts and bring 4 ideas to life in Scratch. Coding Area: Where you assemble coding blocks to create scripts and make your sprites 5 perform actions. It is also known as the script area. 6
Stage: The area where sprites interact and display the results of your code.
Sprite: Characters or objects in your project that you can program to move, talk, and 7 interact.
4
CB_Grade 5.indb 4
11/29/2023 1:38:54 PM
Backdrop: Various backgrounds for the stage to set the project’s setting, customisable 8 and importable. 9
Go Button: The green flag button runs your project, bringing your code to life.
10 Stop Button: The red circle button stops or pauses your project when it is running. Sprites Pane: Located under the stage, it contains details about sprites, including name, 11 size, and location. Here, you can edit, upload, or change sprites.
Do It Yourself 1B Match the following. A
B Sprites Pane
Coding Area
Sprite Block Panel
Go Button
Adding a Sprite
The main character that performs all the action in your project is known as a Sprite. The default sprite in Scratch is a Cat. You can change or add more sprites to your project per your choice. Before adding a new sprite you can delete the existing sprite by clicking on delete button in the sprites pane.
Chapter 1 • Introduction to Scratch 3.0
CB_Grade 5.indb 5
5
11/29/2023 1:38:54 PM
Follow the given steps to add a sprite in your project: 1
Click on the Choose a Sprite button.
2
Select Choose a Sprite. Upload Sprite Surprise Paint Choose a Sprite Choose a Sprite button.
3 The Choose a Sprite dialog box appears. Click on the desired sprite. The sprite appears on the stage.
If you want to draw your own sprite or upload an already drawn sprite, Scratch provides Paint and Upload Sprite options to do so. In our case, we have selected the Robot sprite.
Changing Costume
Changing costumes allows you to give your sprite a different look, steps for changing costumes in Scratch are: 1
Click on the sprite you want to change the costume for in the Sprites pane.
6
CB_Grade 5.indb 6
11/29/2023 1:38:54 PM
2
Click on the Costumes tab.
3 You will see the following screen. Choose from the available costumes on the left to change the costume.
3
You can also paint a new costume to draw your own sprite.
Animating a Sprite
Now, to animate your sprite in Scratch: 1
Click on the Events category.
2
Drag the when clicked block.
3
Click on the Looks category.
Chapter 1 • Introduction to Scratch 3.0
CB_Grade 5.indb 7
7
11/29/2023 1:38:55 PM
Drag the next costume block and snap it below the when clicked block.
4
Click on the green button. The sprite changes its costume on every click. 5
Think and Tell While you design your costume for your sprite, in your opinion, what colours look the best on your sprite?
Do It Yourself 1C Fill in the blanks. is the main character that performs all the tasks in your project.
1 2
To make our sprite change its costume, we drag the
3
To see a library full of various characters and pictures, we must click
4
In order to change a costume, we first must choose a
5
The
and
block from the Looks category. .
.
blocks are used to animate the costume change of a sprite.
8
CB_Grade 5.indb 8
11/29/2023 1:38:55 PM
Duplicating a Costume
You can make your sprite wear the same costume twice. To duplicate a costume in Scratch for a sprite, follow the given steps: 1 Click on the sprite you want to duplicate a costume for in the Sprites pane. 2
Click the Costumes tab.
3
Click the costume to select it.
4 Right-click the selected costume. A context menu appears. 5 In this menu, click duplicate, and a copy of the costume is created. Scratch gives the duplicated costume with the same name as the sprite along with the suffix 2, 3, or so on. For example, we have duplicated robot-b and so, the duplicated costume’s name will be robot-b2. You can switch between costumes using the switch costume to block. You need to specify the names of the costume in this block.
Do It Yourself 1D Explain the functions of the blocks. 1
2
Chapter 1 • Introduction to Scratch 3.0
CB_Grade 5.indb 9
9
11/29/2023 1:38:55 PM
3
Duplicating a Sprite
Steps to duplicate a sprite in Scratch are as follows: 1
In the Sprites pane, click the sprite you want to duplicate.
2
Right-click the sprite, which opens a menu.
3
Select the duplicate option to create a copy of the selected sprite.
4 The duplicated sprite will appear with the same name as the sprite along with the suffix 2, 3, or so on. For example, on duplicating the Robot sprite, the name will be Robot2, Robot3, and so on. To duplicate a sprite using code: 1
Drag the when clicked block from the Events category.
2
Click the Control category.
3
Drag the create clone of myself block in the script area.
4 Click on the green button. The duplicated sprite will overlap the existing sprite. You can change the location by dragging the sprite. 10
CB_Grade 5.indb 10
11/29/2023 1:38:55 PM
Adding Backdrops
You can add backgrounds, also known as backdrops, to your project to create various settings or scenes for your sprites to interact with. Here’s how you can add a background: 1
Click on the Choose a Backdrop button in the bottom right corner of the interface.
2
Select Choose a Backdrop.
Upload Backdrop Surprise Paint 2 1
3 The Choose a Backdrop dialog box opens. You can scroll through the library to find a backdrop you like.
Chapter 1 • Introduction to Scratch 3.0
CB_Grade 5.indb 11
11
11/29/2023 1:38:56 PM
4
lick the backdrop you want to use from the library. The selected C backdrop replaces the current backdrop on the stage.
If you have a custom backdrop you want to use, click the Upload 5 Backdrop option to import your image as a backdrop. You can also customise and edit backdrops. Click a backdrop in 6 the library to select it, and then use the backdrop editing tools to make changes, add details, or draw your own background.
Backdrop Editing Tools
Changing Backdrops
If you want to change the background while your project is running, you can use special code blocks to do it. 1
Drag the when clicked block from the Events category.
2 Drag the next backdrop from the Looks category and snap it below the when clicked block.
12
CB_Grade 5.indb 12
11/29/2023 1:38:57 PM
Chapter Checkup A
Fill in the Blanks. Hints
backdrops library
stop sign
Scratch
1 To duplicate your costume, you must select your 2
B
C
sprites pane
sprite
.
In case you want to add more backdrops, you will get them from the
.
3
uses colourful blocks with pictures on them to create programs.
4
is represented as a red circle that allows you to stop or pause your project if it is running.
5
is under the stage; it has all details about the sprite.
Who Am I? 1
I’m also known as programming; I give instructions to the computer that it executes.
2
I’m the area in the Scratch window that contains various categories of blocks.
3
I’m a category of blocks that contains the when clicked block.
4
I’m free software that allows you to design your own digital world.
5
I’m the area in the Scratch window where you can code.
Explain the Function of the Icon. 1
2
Chapter 1 • Introduction to Scratch 3.0
CB_Grade 5.indb 13
13
11/29/2023 1:38:57 PM
3 4 5 D
E
Write T for True and F for False. 1
The block panel is where you can find a wide range of coding blocks to use in your scripts.
2
To change a costume, first go to the Code tab.
3
You just need to click the Paint option to create your own backdrop.
4
You can assemble and connect the coding blocks to create scripts in the coding area.
5
You cannot customise a sprite according to your choice.
Answer the Following. 1
What is Scratch 3.0?
2
What is the Sprite Pane?
3
Which option is used to add a sprite to a project?
14
CB_Grade 5.indb 14
11/29/2023 1:38:57 PM
4
What is the Coding area?
5
Write the steps to duplicate a costume in Scratch 3.0?
F
Apply Your Learning. 1 Draw a panda in the Scratch paint editor and use it as a sprite. Also, assign a suitable name to your sprite.
2 Shreya wants to add her school’s playground photo as the background in a Scratch project. Help her upload the background by writing the steps. 3 Meenal has made an amazing design in Scratch but doesn’t know how to duplicate a costume. What should she do? 4 Tanu is making a project in Scratch for her school’s annual day function in which she needs to add the same sprite five times. How can she do this? 5 Seema has created a project in Scratch for the birthday of her son in which she wants to display some photos one by one as the background. Which two blocks should she use to do so?
Chapter 1 • Introduction to Scratch 3.0
CB_Grade 5.indb 15
15
11/29/2023 1:38:57 PM
21
Control and Sensing Blocks
Understanding Control and Sensing Blocks Scratch is an event-driven programming language. This means that actions are triggered by events, such as clicking a sprite or pressing a key, making it easy to create interactive animations and games. In this chapter, we are diving into the exciting world of Scratch, a special computer language that helps us think and solve puzzles. We will understand how to use control and sensing blocks.
Project: Using Ask and Answer Block
The Robo Calculator asks a simple question on the stage and waits for the response given by the user. If the user gives the correct answer, Robo Calculator provides positive feedback; otherwise, it provides encouragement to try again.
Did You Know? Scratch is free to use and open source, making it accessible to anyone with an internet connection. This encourages inclusivity and learning for all.
Project Setup Open Scratch and then continue with your project. In the previous chapter, we had set up the ‘Robo’ sprite and the backdrop to ‘Xy-grid-30px’, as shown in the figure below:
16
CB_Grade 5.indb 16
11/29/2023 1:38:58 PM
Control Blocks
The blocks from the Control category are also called conditional blocks. They allow a program to perform a test based on a given condition and then take actions based on the result of that test. Let us see the usage of some of the blocks from the Control category, as explained in the table below: if-then
This block is used to check the given condition. If the condition is true, the blocks inside the if-then block are executed; if it is false, the blocks are not executed.
if-then-else
This block is an extension of the if-then block. If the given condition is true, then the blocks inside the ifthen section are executed. If the condition is false, then the blocks inside the else part are executed.
repeat
The repeat block in the Control category repeats all the blocks inside it the number of times specified in the repeat block.
forever
The forever block repeats the actions forever, never stopping until you click the red Stop button on the screen to end your program.
repeat until
The repeat until block repeats the actions specified by the blocks inside it until a given condition is true. When the condition becomes false, the loop execution stops.
wait
This block is used to wait for n number of seconds, where n is any integer.
wait until
The wait until block pauses the script until the specified condition is true.
stop all
This block stops all the running scripts.
Did You Know?
Scratch can be used on various platforms, including web browsers, Windows, macOS, and Linux, making it versatile and widely compatible.
Chapter 2 • Control and Sensing Blocks
CB_Grade 5.indb 17
17
11/29/2023 1:38:58 PM
Do It Yourself 2A Fill in the blanks. 1
In Scratch programming, the if-then block is used for making decisions based on a
2 To create a loop that repeats an action a certain number of times, you can use the
. block.
Sensing Blocks
The Sensing blocks are used to sense conditions in the environment, such as the background colour or the sprite touching status. For example, you can use the touching color block to check if a sprite is touching a specific colour on the stage. These blocks are cyan in colour and are used to detect various factors in a project. In Scratch, there are several categories of Sensing blocks that allow you to gather information about the environment and user input. Let us look at the usage of some of the Sensing blocks in the following table: touching color ? touching ask and wait answer key pressed?
Determines if a sprite is touching a specific colour on the stage.
Checks if a sprite is currently touching another sprite or a colour. Displays a message or a question for the user and waits for their input.
Retrieves the response given by the user to a previous ask and wait block.
Determines if a specific key on the keyboard is currently being pressed.
reset timer
Resets the timer to zero, which can be used to measure the elapsed time.
timer
Provides the time in seconds since the project started or since the reset timer block was used.
Working of the Project
The Robo Calculator asks some questions through the ask and wait block. It then checks the answer given by the user through the answer block and then the answer is displayed. Follow the given steps and create a script to make the Robo Calculator check whether the answer to the question is correct. These steps can be performed using Control blocks in Scratch. 1
Drag this when clicked block from the Events category to the Coding area.
18
CB_Grade 5.indb 18
11/29/2023 1:38:58 PM
2 Add the ask and wait block from the Sensing category below the when clicked block to ask the question, as shown below.
3 Now, type the question you want to ask inside the ask and wait block. After that, drag the if… then… else block from the Control category to decide whether the response given by the user is correct or not.
Replace “Hello” with “Addition of 23 + 50 is ?” for the answer.
4 Drag the equal to comparison block from the Operators category to the condition area of the if… then… else block.
Chapter 2 • Control and Sensing Blocks
CB_Grade 5.indb 19
19
11/29/2023 1:38:58 PM
5 Drag the answer block from the Sensing category to the left box of the equal to block.
6 Click the green flag button to test the script. When you click the green flag button, the Robo sprite asks the question and then waits for the answer from the user, as shown in the figure below.
7 Click the Looks category and then drag the say for 2 seconds block for the true condition of the if... then... else block, as shown in the figure below.
20
CB_Grade 5.indb 20
11/29/2023 1:38:59 PM
8 This step helps ensure that the Robo Calculator displays the result when it provides the correct answer, as shown in the figure below:
Showing the answer when condition is true.
9 Click the green flag button and check whether the script is working perfectly or not, as shown in the figure below.
Now, Add one more say for 2 seconds block from the Looks category for the false 10 condition under the else part, as shown in the figure below.
Showing the answer when condition is false.
Chapter 2 • Control and Sensing Blocks
CB_Grade 5.indb 21
21
11/29/2023 1:38:59 PM
11 Run the script and verify the conditions for the asked question.
12 If you want to repeat the process multiple times, you can use Control blocks to create loops, as per the requirement. It also requires some variables to store values and make the game dynamic. A sample code for the same is shown in the figure below:
For repetition of the same process multiple times, use the “repeat” block.
22
CB_Grade 5.indb 22
11/29/2023 1:39:00 PM
Do It Yourself 2B Look at the following code and fill in the blanks.
1 In the above Scratch code, the wait () seconds block is a part of the program to .
category, and it allows the
2 The say (Hello!) for (1) seconds block in the Looks category displays a ‘Hello’.
that includes the word
Coding Challenge Create a game in Scratch with the name ‘Colour Match’.
Objective: The player must click a sprite that matches a specific colour. Instructions: 1
Create two sprites: a ‘Colour Matcher’ sprite and a ‘Colour Target’ sprite.
2
Create a script for the ‘Colour Matcher’ sprite to change its costume to a random colour when clicked using a Sensing block.
3
Create a script for the ‘Colour Target’ sprite to change its costume to a specific colour using a Sensing block.
4
Use Conditional blocks to check if the ‘Colour Matcher’ sprite costume matches the ‘Colour Target’ sprite costume.
5
If they match, display a message saying ‘You Win!’, using a say block.
6
If they do not match, display a message saying ‘Try Again’, using a say block.
7
Allow the player to click the ‘Colour Matcher’ sprite again to start a new round with a new random colour.
Chapter 2 • Control and Sensing Blocks
CB_Grade 5.indb 23
23
11/29/2023 1:39:00 PM
Chapter Checkup A
Fill in the Blanks. user’s response
Hints
condition
decisions
1 Control blocks in Scratch are primarily used to make 2 The
pause
sensing
in your program.
blocks allow you to check how a sprite is interacting with the stage or other sprites.
3 When using a wait until <condition> block, the program will condition is true.
until the specified
4 The if-then block is used to specify which action is taken if a certain
is met.
5 The ask () and wait block is a combination of a sensing block and a stack block. The ask () and wait block first asks a question to the user and then waits for the . B
Tick () the Correct Option. 1
Which blocks in Scratch are used for making decisions in your program?
a
b
c
d
2
Which sensing block in Scratch is used to check if a sprite is touching a specific colour?
a
c 3
b d
What is the purpose of the if-else block in Scratch?
a It is used to create loops.
b It is used to repeat actions.
c It is used to make decisions based
d It is used to change the background.
on a condition. 4 Which block in Scratch is used to wait for a certain condition to be met before continuing with the program?
a c
b d
24
CB_Grade 5.indb 24
11/29/2023 1:39:00 PM
5 In Scratch, how do you check if a sprite is touching the edge of the stage? a Use the edge detection block.
b Use the touching edge block.
c Use the edge sensing block.
d Use the stage edge block.
C
Who Am I?
1 I’m a block in Scratch that allows you to ask a question to the user and then wait for their response before proceeding with the program.
2 I’m used in Scratch to check if a specific condition is true or false and then make decisions based on the result.
3 I’m a block in Scratch that waits for a certain period of time before allowing the program to continue.
4 I’m a block in Scratch used to check if a sprite is touching a specific colour or object.
5 I’m a type of block in Scratch that helps you create loops and repeat actions. D
Write T for True and F for False. 1 A condition is applied to put a check on a problem. 2 You cannot perform mathematical operations in Scratch. 3 Sensing blocks in Scratch are used to detect conditions associated with sprites and the stage. 4 The ask and wait block in Scratch allows you to ask a question on the screen and stores the keyboard input in the answer block. 5 The control blocks allow you to execute various sets of codes based on whether a specified condition is true or false, while the sensing blocks are used to detect and respond to changes.
E
Answer the Following. 1
What is the purpose of Control (Conditional) blocks in Scratch?
Chapter 2 • Control and Sensing Blocks
CB_Grade 5.indb 25
25
11/29/2023 1:39:01 PM
2 How do Sensing blocks in Scratch help you detect user interactions? Name two Sensing blocks commonly used in Scratch projects. 3 Explain the difference between the if and if-else Control blocks in Scratch. 4 How can you use Sensing blocks to create interactive games in Scratch? 5 What is the role of the ask and wait block in the Sensing category? F
Apply Your Learning. 1 Create a Scratch project where a character moves left when the ‘A’ key is pressed and right when the ‘D’ key is pressed. Which Sensing block should you use, and how will you implement this?
2 In a Scratch game, you want to make an enemy sprite disappear when your player sprite touches it. Describe the Conditional blocks and logic you would use to achieve this. 3 Build a simple quiz game in Scratch where the program asks a question using the ‘ask and wait’ block and responds differently based on whether the user’s answer is correct or not.
26
CB_Grade 5.indb 26
11/29/2023 1:39:01 PM
4 Create an animation in Scratch in which a sprite changes its costume when the mouse pointer is hovering over it. Which Sensing and Control blocks would you use for this task? 5 Design a Scratch project that simulates a traffic light with three different colours (red, yellow, and green) using Control blocks. How would you make the lights change automatically with appropriate timing?
Chapter 2 • Control and Sensing Blocks
CB_Grade 5.indb 27
27
11/29/2023 1:39:01 PM
31
Using Variable and Mathematical Blocks in Scratch
Variable and Mathematical Blocks
Scratch is a free block-based programming language developed by Massachusetts Institute of Technology (MIT). This language allows you to create interactive stories, animations, games, music, and art, and share your creations on the web. In the previous chapter, you have learnt about various conditional and sensing blocks. Let us learn about variables and mathematical blocks in this chapter. Project: Solving Maths Puzzles Robo Calculator must solve various mathematical expressions, including addition, subtraction, multiplication, and division to progress in the story. Robo Calculator
Variable Blocks
Computers cannot assign themselves a value like we do, but we can code them to store a value using Variable blocks. Variable blocks are the blocks that help a computer to store a value that can be changed throughout a project. Variables can be used to store numbers and text. In Scratch, a variable can contain two types of values: numeric and textual or string. Numeric Variable
It is used to store numbers.
Did You Know? String Variable
It is used to store text.
The first ever Scratch project is ‘Weekend’.
Adding a Variable
To make Robo Calculator add a variable, we can just add the variable block. Steps to make Robo Calculator add a variable are:
28
CB_Grade 5.indb 28
11/29/2023 1:39:01 PM
1
Open Scratch.
2 Drag the when clicked block from the Events category to the script area. 3 Drag the ask and wait block from the Sensing category below the when clicked block. 4 Set the text in the ask and wait block to ‘What is the first number?’. 5
Select the Variables category.
6
Click the Make a Variable button.
7
The New Variable dialog box appears. Assign a name to the new variable.
8
Click OK. The variable is added to the list.
Now, we know how to add a variable, so let us explore how to set a variable value.
Setting Variable Value
To make Robo Calculator set a variable value, we can just add the set variable to 0 block. To make Robo Calculator set a variable value:
Chapter 3 • Using Variable and Mathematical Blocks in Scratch
CB_Grade 5.indb 29
29
11/29/2023 1:39:01 PM
1
Drag the set variable to block from the Variables category to the script area.
2 The variable drop-down menu lists all the variables, and you can then select the variable you want to set the value of.
30
CB_Grade 5.indb 30
11/29/2023 1:39:02 PM
3
Type the value you want to set the variable to. The value can be a number or text.
Click here to change the value
Changing the Variable Value
To make Robo Calculator change a variable value, we can just edit the set variable to 0 block. To make Robo Calculator change a variable value: 1
Drag the change variable by block from the Variables category to the script area.
Chapter 3 • Using Variable and Mathematical Blocks in Scratch
CB_Grade 5.indb 31
31
11/29/2023 1:39:02 PM
2
Select the variable whose value you want to change in the change variable by block.
3
Type the new value by which you want to change the variable value.
Click here to change the value
Similarly, create two more variables named ‘number 2’ and ‘result’.
Mathematical Blocks
Mathematical blocks help a computer to perform mathematical operations. These blocks are found under the Operators block category. 32
CB_Grade 5.indb 32
11/29/2023 1:39:02 PM
The four most commonly used mathematical blocks are: Block
Name
Description
Addition
It is used to add two numbers.
Subtraction
It is used to subtract a number from another number.
Multiplication
It is used to multiply two numbers.
Division
It is used to divide a number by another number.
Discuss
The major differences between the Division and Multiplication blocks.
Adding Two Given Numbers
Instead of changing the variable value, we used the answer block to set the value of the number 1 variable. To make Robo Calculator add two numbers: 1 Drag the answer block from the Sensing category to the value area of the set variable to block, to set the value of the number 1 variable. 2 Again, drag the ask and wait block to the previous block. 3 Set the What is the second number? text to the ask and wait block. 4 Drag the set variable to block in the code and then select the number 2 variable from its drop-down menu. 5 Drag the answer block to the value area of the set variable to block, to set the value of the number 2 variable. 6 Again, drag the set variable to block in the code and then select the result variable from its drop-down menu. 7 Click the Operators category. 8 Drag the addition block to inside the set variable to block, to set the value of the result variable. Chapter 3 • Using Variable and Mathematical Blocks in Scratch
CB_Grade 5.indb 33
33
11/29/2023 1:39:02 PM
9 Drag the number 1 and number 2 variables from the Variables category to the left and right boxes of the addition block.
10 Click the green flag to run Robo Calculator.
Click here to run
Subtracting a Number from Another Number Similar to making Robo Calculator add two numbers, we can also make Robo Calculator subtract a number from another number. We can just add the subtraction operator block.
Steps to make Robo Calculator subtract a number from another number are: 1 Drag the subtraction block from the Operators category to inside the set variable to block. 34
CB_Grade 5.indb 34
11/29/2023 1:39:03 PM
2 Drag the number 1 and number 2 variables from the Variables category to the subtraction block.
3
Click the green flag to run Robo Calculator.
Click here to run
Multiplying Two Numbers
Similar to making Robo Calculator add two numbers, we can also use it to multiply two numbers. We can just add the multiplication block. Steps to make Robo Calculator multiply two numbers are: 1 Drag the multiplication block from the Operators category to inside the set variable to block.
Chapter 3 • Using Variable and Mathematical Blocks in Scratch
CB_Grade 5.indb 35
35
11/29/2023 1:39:03 PM
2 Drag the number 1 and number 2 variables from the Variables category to inside the multiplication block.
3
Click the green flag to run Robo Calculator.
Click here to run
Dividing Two Numbers
Similar to making Robo Calculator add two numbers, we can also make it divide a number from another number. We can just add the division block. Steps to make Robo Calculator divide a number from another number are: 1 Drag the division block from the Operators category to inside the set variable to block.
36
CB_Grade 5.indb 36
11/29/2023 1:39:03 PM
2 Drag the number 1 and number 2 variables from the Variables category and place them inside the division block.
3 Click the green flag to run Robo Calculator. Click here to run
Do It Yourself 3A Complete the following length-finder game project.
Steps for making this length finder game are: Drag the 1
from the
category to the script.
Chapter 3 • Using Variable and Mathematical Blocks in Scratch
CB_Grade 5.indb 37
37
11/29/2023 1:39:04 PM
2 Drag the
from the
3 Drag the then wait.
block from the Sensing category to ask ‘Give me one word to find its length’ and
4 Add the
block from the Variables category to set the word to answer.
category and then initialise both x and y with 0.
5 Drag the set word length block from the inside it. 6
Drag the
category and then put the length of the block
block from the Sensing category to place it inside the
block.
Chapter Checkup A
Fill in the Blanks. four
Hints
B
variables
1
Variable blocks are blocks that help a computer to
2
In Scratch, there are mainly
3
Mathematical blocks are present in the
4
Make a Variable button that is present in the
5
The Addition block is used to
store
add
operators
a value.
types of mathematical blocks. category. category.
two numbers.
Tick () the Correct Option. 1
Which mathematical block is used to divide two numbers?
a
b
c
d
2
Which block is used to store a value?
a Mathematical block
b Ask block
c Variable block
d Addition block
3
In Scratch, how many types of variables are there?
a Three
b Four
c Two
d One
38
CB_Grade 5.indb 38
11/29/2023 1:39:04 PM
4
The subtraction block is present in the
category.
a Sensing
b Operators
c Motion
d Variables
5
In which category is the change variable by block present?
a Variables
b Sensing
c Operators
d Not present
C
Who Am I? Who Am I?
What I Do? I am used to store text. I am used to divide two numbers. I am used to add two numbers. I am used to store numbers.
D
E
Write T for True and F for False. 1
A variable is changeable at any time.
2
The subtraction block subtracts a number from another number.
3
The multiplication block adds two numbers together.
4
The division block divides a number by another number.
5
The variable block is used to store operators.
Answer the Following. 1
What are variable blocks?
2
How many types of variables can be created in Scratch?
Chapter 3 • Using Variable and Mathematical Blocks in Scratch
CB_Grade 5.indb 39
39
11/29/2023 1:39:04 PM
3
What are mathematical blocks?
4
How many types of mathematical blocks are there in Scratch?
5
What is the addition block used for?
F
Apply Your Learning. 1 Describe the use of the following block.
2 What is the purpose of using the block given below? 3
What is the purpose of using the block given below?
40
CB_Grade 5.indb 40
11/29/2023 1:39:05 PM
4
Observe the script and write down what it will do.
5
Observe the script and write down what it will do.
Chapter 3 • Using Variable and Mathematical Blocks in Scratch
CB_Grade 5.indb 41
41
11/29/2023 1:39:05 PM
41
Using Comparison Blocks and Random Blocks in Scratch
Comparison Blocks
Computers cannot make comparisons like we do. But we can code them to make comparisons using Comparison blocks. Comparison blocks are the blocks that help a computer make comparisons, depending on the statements or equations it checks.
In Scratch, we have three comparison blocks in the Operators category: Blocks
Name
Did You Know? The first version of Scratch was implemented in ‘Squeak’.
Description
Equal
It returns true when the two numbers are equal; it returns false when they are not equal.
Greater than
It returns true when the first number is greater than the second; otherwise, it returns false.
Less than
It returns true when the first number is less than the second; otherwise, it returns false.
Check Whether the Given Numbers Are Equal or Not
To make Robo Calculator check whether the given numbers are equal or not, we can just add the equal block. Steps to make the Robo calculator check the given numbers are equal or not: 1 Similar to the project created in the previous chapter, create three variables named number 1, number 2, and compare. 2
Drag and drop the when clicked block on the script area.
3 Display the appropriate messages to take the value of the number 1 and number 2 variables using the ask block. 4
Set the values of the number 1 and number 2 variables, using the answer block.
5
Again, drag and drop the ask and wait block.
6 Set the text Do you want to check whether the given numbers are equal or not? in the ask and wait block.
42
CB_Grade 5.indb 42
11/29/2023 1:39:05 PM
7 Drag and drop the set variable to block from the Variables category and select the compare variable from its drop-down menu. 8 Drag and drop the answer block to the value area of the set compare to block. 9
Click the Control category.
10 Drag and drop the if… then… else block under the set compare to block.
11 Click the Operators category. 12 Drag and join the equal block inside the if… then… else block.
Chapter 4 • Using Comparison Blocks and Random Blocks in Scratch
CB_Grade 5.indb 43
43
11/29/2023 1:39:06 PM
13 Drag the number 1 and number 2 variables from the Variables category to inside the equal operator.
14 Click the Looks category. 15 Drag the say block and put it between the white space of the if… then… else block. 16 In the say block, type the message: Hurray! Given Numbers are equal. Similarly, put the say block after the else and type the message: Oops! Given Numbers are not equal.
44
CB_Grade 5.indb 44
11/29/2023 1:39:06 PM
17 Now, click the green flag to run your Robo Calculator.
Click here to run
Hurray! Given Numbers are equal
Check Whether the First Number is Less Than the Second Number or Not
To make Robo Calculator check whether the first number is less than the second number or not, we can just add the less than operator. Steps to make Robo Calculator check if the first number is less than the second number or not are: 1 Drag and join the if… then… else block from the Control category under the set compare to answer block.
Chapter 4 • Using Comparison Blocks and Random Blocks in Scratch
CB_Grade 5.indb 45
45
11/29/2023 1:39:06 PM
2 Drag and join the less than block from the Operators category inside the if… then… else block.
3 Drag number 1 and number 2 variables from the Variables category to inside the less than operator.
4
Click the Looks category.
46
CB_Grade 5.indb 46
11/29/2023 1:39:07 PM
5
Drag the say block and put it between the white space of the if… then block.
6
Double-click the say block to type the message: Number 1 is less than Number 2.
7 Similarly, put the say block after the else and double-click it to type the message: Number 1 is not less than Number 2.
8
Now, click the green flag to run your Robo Calculator.
Click here to run
Chapter 4 • Using Comparison Blocks and Random Blocks in Scratch
CB_Grade 5.indb 47
47
11/29/2023 1:39:07 PM
Check Whether the First Number is Greater Than the Second Number or Not
To make Robo Calculator check whether the first number is greater than the second number or not, we can just add the greater than block. Steps to make Robo calculator check if the first number is greater than the second number or not are: 1 Drag and join the if… then… else block from the Control category to under the set compare to answer block.
2
Drag the greater than from the Operators category to join it inside the if… then block.
48
CB_Grade 5.indb 48
11/29/2023 1:39:07 PM
3 Drag the number 1 and number 2 variables from the Variables category to inside the greater than operator.
4
Click the Looks category.
5 Drag the say block to between the white space of if… then block. 6 Double-click the say block to type the message: Number 1 is greater than Number 2. 7 Similarly, put the say block after the else block and double-click it to type the message: Number 1 is not greater than Number 2.
Chapter 4 • Using Comparison Blocks and Random Blocks in Scratch
CB_Grade 5.indb 49
49
11/29/2023 1:39:08 PM
8
Now, click the green flag to run your Robo Calculator.
Click here to run
Random Block
The Random block is a block that helps a computer pick a random number between two numbers that you have chosen.
Using a Random Block to Add Numbers
To make Robo Calculator use a random block, we can just add the pick random operator. Steps to make the Robo calculator use a random block are: 1
Click the Events category.
2
Drag the when clicked block to the script area.
50
CB_Grade 5.indb 50
11/29/2023 1:39:08 PM
3
Click the Motion category.
4
Drag the go to x:0, y:0 block to the script area.
5 Drag and drop the say block two times from the Looks category and then fill the first block with the text Welcome to the Robo Calculator and the second one with the text I will generate the random numbers and ask you to add them together.
6
Drag the set variable to the block from the Variable category.
Chapter 4 • Using Comparison Blocks and Random Blocks in Scratch
CB_Grade 5.indb 51
51
11/29/2023 1:39:08 PM
7
Set the text add in the set variable to block.
8 Drag the two more set variable to blocks from the Variables category to the script area. 9 Select the number 1 and number 2 from the drop-down menu of both set variable to blocks, respectively.
10 Drag the two pick random 0 to 0 blocks from the Operators category to the value area of the set variable to blocks.
52
CB_Grade 5.indb 52
11/29/2023 1:39:09 PM
11 Set the limit from 1 to 9999.
12 Drag the say block from the Looks category and then fill it with the text What is the sum of number 1 and number 2?
Chapter 4 • Using Comparison Blocks and Random Blocks in Scratch
CB_Grade 5.indb 53
53
11/29/2023 1:39:09 PM
13 Drag the wait 1 seconds block from the Control category to under the say block.
14 Fill the wait block with 5 seconds. 15 Drag the ask and wait block from the Sensing category and fill it with the text ‘Your answer’.
54
CB_Grade 5.indb 54
11/29/2023 1:39:09 PM
16 Drag the set answer to block from the Variables category. 17 Put the addition operator block from the Operators block inside the set answer to block. 18 Drag the number 1 and number 2 variables from the Variables category and then put them inside the addition operator block.
19 Drag the say block from the Looks category and then fill it with: Hurray! You have given the correct answer.
Chapter 4 • Using Comparison Blocks and Random Blocks in Scratch
CB_Grade 5.indb 55
55
11/29/2023 1:39:09 PM
Now, click the green flag to run your Robo Calculator. 20
Coding Challenge Help Dino avoid obstacles to achieve a high score.
Click here to run
Do It Yourself 4A Complete the following Clicker Game Project.
Steps for making this clicker game are: 1 Drag the
block from the
category to the script area.
2
Add the
block from the
category.
3
Drag the
block from the Motion category to move the balloon in a random direction.
4
Add the
block for the 2 seconds block from the Control category.
5
Drag the
block from the
6
Add the
block from the Sound category to make the sound when the sprite gets clicked.
7 Now, add the player clicks the sprite.
category to add in the script.
block from the Variables category to change the score by 1 whenever the
56
CB_Grade 5.indb 56
11/29/2023 1:39:10 PM
Discuss
How do the sound blocks make your project feel different?
Chapter Checkup A
Fill in the Blanks. Hints
compare
operators
random numbers
1 A Random block helps a computer to pick
equal, less than, greater than
between two numbers that you have chosen.
2 In Scratch, we have three comparison blocks in the operator category: and .
B
3
Comparison blocks are used to
4
A random block is present in the
values or numbers. category.
Tick () the Correct Option. 1
In Scratch, what type of blocks are used to show the equal operator?
a
b
c
d None of these
2
Which operator is used to show that number 1 is bigger than number 2?
a addition
b less than
c greater than
d pick random
3
Random numbers can be used in script from the
category.
a Sensing
b Motion
c Operators
d Variables
4
Comparison blocks help a computer
two numbers.
a sense
b compare
c add
d multiply
5
In Scratch, how many types of comparison blocks are there?
a five
b six
c three
d eight
Chapter 4 • Using Comparison Blocks and Random Blocks in Scratch
CB_Grade 5.indb 57
,
57
11/29/2023 1:39:10 PM
C
Who Am I? Who Am I?
What I Do? I return true when the first number is greater than the second; otherwise, I return false when it is not. I am a block that picks a random number between two numbers that you have chosen. I return true when the first number is less than the second; otherwise, I return false when it is not. I return true when the two numbers are equal; otherwise, I return false when they are not.
D
E
Write T for True and F for False. 1
Comparison blocks can be used to generate random numbers.
2
A pick random block always returns the same number.
3
Comparison blocks can be used to compare two values or expressions.
4
Random blocks can be used to make Scratch projects more fun and engaging.
Answer the Following. 1
What are Comparison blocks?
2
What is a random block?
3
What are the different types of Comparison blocks?
4
What is the greater than operator used for?
5
What is the equal operator used for?
58
CB_Grade 5.indb 58
11/29/2023 1:39:10 PM
F
Apply Your Learning. 1
Observe the script and write down what it will do.
2
What is the purpose of using the following block in the script?
3
What is the purpose of using the block in the script?
4
Describe the role of the block given below.
5 Create a game in which the player controls a snake that needs to catch randomly moving pieces of food. When the snake captures the food, the player’s score should increase. The objective of the game is to maximise the score by guiding the snake to catch as much food as possible. Chapter 4 • Using Comparison Blocks and Random Blocks in Scratch
CB_Grade 5.indb 59
59
11/29/2023 1:39:11 PM
About the Book This coding book is supplementary to the main “Mel n Conji” content book. This book represents a 21st-century approach to learning coding concepts and developing computational thinking and problem-solving skills. To prepare students for the digital age, the curriculum is interwoven with well-thought-out concept graduation with real-life examples and practice problems.
Special Features • Illustrative approach: Concepts in coding and computer science are delivered through pictorial representations and learner-friendly approaches. • Learning through real-life examples: Age-appropriate examples that enable learners to relate to the concept and learn about the unknown from the known. • Extensive practice: Multiple practice scenarios to reinforce learnings. • Coding challenges: Includes projects through which learners can demonstrate their learning outcomes in coding and computer science.
About Uolo Uolo partners with K-12 schools to bring technology-based learning programs. We believe pedagogy and technology must come together to deliver scalable learning experiences that generate measurable outcomes. Uolo is trusted by over 10,000 schools across India, South East Asia, and the Middle East.
Singapore
|
CS_CB_Coding_Grade5_Cover.indd All Pages
Gurugram
|
Bengaluru
|
hello@uolo.com �199
© 2024 Uolo EdTech Pvt. Ltd. All rights reserved.
NEP 2020 based
|
NCF compliant
|
Technology powered
03/12/23 8:02 PM