Programming in Scratch
In Class 8, we move a step ahead. We will now learn to make projects more interactive through the use of logic, conditions and variables.
Scratch is used to make games and projects that react to user input.
Using Variables
Information is stored in a program using a variable.
For example:
- Storing a player's score
- Counting the number of steps
- Saving a timer value
To create a variable:
- Go to the "Variables" section.
- Click "Make a Variable".
- Give it a name like "Score".
Now you can change the score in the game.
Using Operators
Calculations and comparisons are done with the assistance of operators.
They are used for:
- Addition (+)
- Subtraction (-)
- Finding out whether numbers are equal.
- Comparing values
Example:
If Score > 10, show "You Win".
Operators help the programme in making decisions.
Conditional statements (If and If-Else)
Conditions help the program in making decisions.
If Block
The programme will act only if the condition is true.
Example:
If the ball touches → add points.
If-Else Block
From these two options, the program will select one.
Example:
If score > 10 → Show "Winner"
Else → Show "Try Again"
Programs are made smarter by conditions.
Loops (Repeat and Forever)
Actions are repeated by use of loops.
- Repeat – runs a block for a fixed number of times.
- Forever – This will repeat until the programme is stopped.
Ask and Answer (User Input)
This allows the user to input an answer.
Example:
- Ask, "What is your name?"
- Put the answer in a variable.
- Say "Hello" + name
Now, the programme becomes interactive.
Broadcasting Messages
The broadcast is utilised where sprites need communication.
For example:
- When a sprite completes its task, it leaves a message.
- Another sprite receives that message and starts moving.
In a project, several sprites are controlled with the help of broadcasting.
Creating a Simple Game
To create a basic game:
- Add a sprite
- Use motion blocks
- Add a score variable
- Increase score using conditions.
- Add a winning message
This will help to make your project more interesting and interactive.
The importance of Programming in Scratch
Scratch helps students:
- Think logically
- Understand problem-solving
- Learn basic coding concepts
- Construct basic games and projects
It equips students with higher-level programming languages.
QUIZ FOR PROGRAMMING IN SCRATCH
1. The Scratch game tracks the points that the player has, and the value is changed whenever a coin is gathered by the player. Which scratch feature stores the values?
A) Sprite
B) Variable
C) Costume
D) Broadcast
Answer: B) Variable
2. The condition is written by a programmer:
If Score -> 10 -> Show "Winner"
What type of Scratch block plays the greater part in checking this condition?
A) Motion Blocks
B) Operators
C) Looks Blocks
D) Sound Blocks
Answer: B) Operators
3. A checking block in a Scratch game tests an anatomical condition and performs one action when it is true and another when it is false. What is the control structure that does this?
A) Repeat Block
B) Forever Block
C) If-Else Block
D) Broadcast Block
Answer: C) If-Else Block
4. A game sprite has to take 10 steps, and then it should stop. Which loop is most suitable?
A) Forever
B) Repeat
C) Broadcast
D) Wait
Answer: B) Repeat
5. In a Scratch animation, a sprite will constantly dance until the program is terminated. What loop block is to be employed?
A) Repeat
B) If-Else
C) Forever
D) Ask Block
Answer: C) Forever
6. One of the Scratch programs requires the player to enter his/her name and then displays "Hello Alex!" using the entered response. What is the attribute that allows the program to be fed by this input?
A) Variables
B) Operators
C) Ask and Answer
D) Broadcast
Answer: C) Ask and Answer
7. A Scratch project is created whereby, when the cat sprite catches a ball, it sends a message to another sprite to start moving. What is the trick that helps sprites to speak this way?
A) Variables
B) Broadcasting
C) Motion Blocks
D) Costumes
Answer: B) Broadcasting
8. What type of Scratch block is primarily used to make decisions based on conditions by the program?
A) Looks Blocks
B) Control Blocks
C) Motion Blocks
D) Sound Blocks
Answer: B) Control Blocks
9. A Scratch game involves the showing of a score +1 every time one gains a point. What type of blocks does this calculation use?
A) Motion Blocks
B) Operators
C) Control Blocks
D) Looks Blocks
Answer: B) Operators
10. What is the most crucial step in the creation of a basic Scratch game?
A) Add a sprite and change the score with variables.
B) Add many backgrounds only
C) Remove all control blocks
D) Use only sound blocks
Answer: Add a sprite and change the score with variables.