How to Use Operator Blocks in Scratch | Full Guide with Live Coding & Examples

Scratch Tutorial

Introduction: Operator Blocks in Scratch

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.

What You Will Learn:

This comprehensive guide teaches you how to:

  • ✅ Perform mathematical operations with arithmetic operators
  • ✅ Generate random numbers for dynamic behavior
  • ✅ Compare values and make decisions
  • ✅ Combine conditions with logical operators
  • ✅ Manipulate text with string operators
  • ✅ Use advanced math functions like modulus and rounding
  • ✅ Build practical projects like calculators and games

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.

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 (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 Use Cases
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

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

Odd/Even Number Checker (Using Modulus)

Objective:

Check if a number is even or odd using the mod operator.

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

Enhancement Features

1. Input Validation

if > then
  say [Please enter a valid number!]
end

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!]
end

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)
end

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, apply the Pick Random block for dynamic behavior, perform comparisons using Comparison Operators, create logic using Boolean Operators like AND, OR, and NOT, manipulate text with String Operators, and perform advanced operations with Modulus, Round, and Absolute Value.

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 and subscribe to Kodex Academy for more Scratch content!

Visit kodexacademy.com for more tutorials.

Next Steps: 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!

Further Reading & Links