Introduction: Operator Blocks in Scratch
Watch the full tutorial here – How to Use Operator Blocks in Scratch | Full Guide with Live Coding & Examples | Kodex Academy
In the world of block-based coding, Scratch stands out as one of the best platforms for beginners to learn programming logic through interactive games, animations, and applications. One of the most powerful features in Scratch is its Operator Blocks — essential for handling math operations, logic comparisons, and string manipulations.
In this comprehensive Scratch programming tutorial, brought to you by Kodex Academy, we’ll explore:
- What operator blocks are
- How to use math operators in Scratch
- Building a calculator
- Making logic-based games
- Working with strings
- Enhancing Scratch games using operator blocks
Whether you’re building a game in Scratch or learning how to use operator blocks in Scratch, this guide has everything you need.
What Are Operator Blocks in Scratch?
Operator blocks in Scratch are green-colored blocks used to:
- Perform mathematical operations
- Create logic conditions
- Handle text (string) manipulation
- Introduce randomness
These blocks are crucial when you need decision-making logic, such as checking if a player wins a game, solving a math problem, or responding to user input.
Watch this section in the video: Operator Blocks Overview – YouTube
Operator Blocks in Scratch: Step-by-Step Coding
1. Arithmetic Operators in Scratch
Used for basic math calculations: addition, subtraction, multiplication, and division.
Addition
set [result v] to ((5) + (3)) // Result = 8
say (result)
Subtraction
set [result v] to ((10) - (4)) // Result = 6
say (result)
Multiplication
set [result v] to ((6) * (7)) // Result = 42
say (result)
Division
set [result v] to ((20) / (5)) // Result = 4
say (result)
Use Case:
Build a calculator in Scratch to let users perform these operations dynamically.
2. Pick Random Operator in Scratch
Used to generate random numbers within a specified range — useful in games and animations.
Example:
set [randomNumber v] to (pick random (1) to (10))
say (join [Your lucky number is: ] (randomNumber))
Use Case:
Create a number guessing game or randomize enemy movement in a game.
3. Comparison Operators in Scratch
Used to compare values and return either true
or false
.
Greater Than or Less Than
if <(score) > (50)> then
say [You passed!]
else
say [Try again!]
end
Equal To
if <(answer) = (10)> then
say [Correct!]
else
say [Wrong answer.]
end
Use Case:
Evaluate game conditions like winning or losing based on score or timer.
4. Logical (Boolean) Operators in Scratch
Used to combine or negate conditions.
AND
if <<(score) > (50)> and <(level) = [final]>> then
say [Game Completed!]
end
OR
if <<(key space pressed?)> or <(key up arrow pressed?)>> then
change y by (10)
end
NOT
if <not <(lives) > (0)>> then
say [Game Over!]
end
Use Case:
Build advanced game logic where multiple conditions need to be met.
5. String Operators in Scratch
Used for text (string) manipulation, useful in quizzes, chats, or name-based logic.
Join Strings
say (join [Hello, ] [Alex]) // Output: Hello, Alex
Letter of a Word
say (letter (1) of [Scratch]) // Output: S
Length of String
say (length of [Scratch]) // Output: 7
Contains?
if <[Scratch] contains [t]> then
say [Yes, 't' is in Scratch!]
end
Use Case:
Create a program that reads user names or builds a typing game.
6. Advanced Math Functions in Scratch
These are mathematical operators used for more complex calculations.
Modulus (Remainder)
if <((number) mod (2)) = (0)> then
say [Even Number]
else
say [Odd Number]
end
✅ Use Case: Even/Odd number checker
Round
say (round (4.7)) // Output: 5
say (round (4.2)) // Output: 4
✅ Use Case: Display whole numbers in score systems or quizzes.
Absolute (Abs)
say (abs (-20)) // Output: 20
✅ Use Case: Distance calculations or physics-based games.
Operators Table
Operator Type | Example Code | Use Case |
---|---|---|
Arithmetic | ((5) + (3)) | Calculator, Score calculation |
Pick Random | (pick random (1) to (100)) | Games, AI randomness |
Comparison | <(score) > (50)> | Game decision-making |
Logical (Boolean) | <<condition1> and <condition2>> | Game level logic |
String | (join [Hello ] [World]) , (length of [Hello]) | Chat apps, Text analysis |
Modulus | ((number) mod (2)) | Odd/Even checker |
Round | (round (3.6)) | Clean display of decimal values |
Abs | (abs (-5)) | Game movement, physics |
Hands-On: Make a Calculator in Scratch
Watch the Full Calculator Demo: Scratch Calculator Demo – YouTube
Features:
- Takes two numbers as input
- User selects the operation (+, -, *, /)
- Displays result
Blocks Used:
ask
(Sensing)if-else
(Control)+ - * /
(Operators)set variable
(Variables)
Sample Code:
when green flag clicked
ask [What operation? +, -, *, /] and wait
set [operation v] to (answer)
ask [Enter first number] and wait
set [num1 v] to (answer)
ask [Enter second number] and wait
set [num2 v] to (answer)
if <(operation) = [+]> then
set [result v] to ((num1) + (num2))
else
if <(operation) = [-]> then
set [result v] to ((num1) - (num2))
else
if <(operation) = [*]> then
set [result v] to ((num1) * (num2))
else
if <(operation) = [/]> then
set [result v] to ((num1) / (num2))
end
end
end
end
say (join [Result: ] (result)) for (10) seconds
Learn how to make calculator in Scratch interactively.
Odd/Even Number Checker (Using Modulus)
Objective:
Check if a number is even or odd using the mod operator. Watch the Mod Operator Example
✅ Code:
when green flag clicked
ask [Enter a number:] and wait
set [num v] to (answer)
if <((num) mod (2)) = (0)> then
say [The number is even] for (10) seconds
else
say [The number is odd] for (10) seconds
end
Great example for teaching math operations using Scratch.
Enhancement Features
Here are extra enhancements you can build into your Scratch projects using operator blocks:
1. Input Validation
Make sure the user enters numbers:
if <not <(answer) contains [0,1,2,3,4,5,6,7,8,9]>> then
say [Please enter a valid number!]
2. Custom Result Display with Looks Block
switch costume to [resultDisplay v]
say (join [Your result is: ] (result)) for (5) seconds
3. Game Score Logic with Booleans
if <<(score) > (50)> and <(lives) > (0)>> then
say [Level Complete!]
else
say [Try Again!]
4. Mini Game with Random Numbers
set [target v] to (pick random (1) to (10))
ask [Guess a number from 1 to 10] and wait
if <(answer) = (target)> then
say [Correct! 🎉]
else
say [Wrong! It was ] + (target)
Conclusion: Mastering Operator Blocks in Scratch
Operator blocks are the backbone of logic, math, and text manipulation in Scratch programming. Whether you’re building a calculator, a logic-based game, or a text recognition app, understanding how to use these green-colored blocks unlocks a world of possibilities.
In this tutorial, you learned:
✅ How to use Arithmetic Operators for calculations
✅ How to apply the Pick Random block for dynamic behavior
✅ How to perform comparisons using Comparison Operators
✅ How to create logic using Boolean Operators like AND
, OR
, and NOT
✅ How to manipulate text with String Operators
✅ How to perform advanced operations with Modulus, Round, and Absolute Value
✅ How to build Calculator in Scratch and How to build Odd/Even Number Checker
By mastering these, you’re not just learning Scratch — you’re building computational thinking skills that apply to all programming languages.
Call to Action
- Don’t forget to check out the full video tutorial: How to Use Operator Blocks in Scratch | Full Guide with Live Coding & Examples | Kodex Academy
- Like, comment & share the video
- Visit kodexacademy.com
- subscribe to the Kodex Academy YouTube channel for deeper Scratch content.
Happy coding with Kodex Academy! 🚀
Learn More with Kodex Academy
At Kodex Academy, we’re passionate about helping students learn coding in creative ways. This project teaches more than Scratch—it empowers young minds to build tools that work in the real world.
Explore more:
Stay updated with new content, free tutorials, and coding challenges!
- 🌐 Website: https://kodexacademy.com
- 🌐 Website: https://games.kodexacademy.com
- 💬 WhatsApp Channel: Join Now
- 💼 LinkedIn: Kodex Academy
- 📸 Instagram: @kodex_academy
- 𝕏 Twitter: @Kodex_Academy
- 📢 Telegram: Join Our Channel
- 🔗 Patreon: patreon.com/KodexAcademy
Further Reading & Links
- Scratch Wiki Motion Blocks: https://en.scratch-wiki.info/wiki/Motion_Blocks
- Scratch Programming for Beginners: https://scratch.mit.edu/projects/editor
- Scratch Animation Guide: https://en.scratch-wiki.info/wiki/Animating