UNIT-3 Introduction to Scratch
3.1 Scratch: A Graphical Programming Language
• Scratch is a block-based visual programming language.
• No typing of long code – uses drag-and-drop puzzle-like blocks.
• Developed by MIT Media Lab.
• Used to create animations, games, and interactive projects.
3.2 Scratch Programming Environment
Main parts of the Scratch interface:
1. Stage – Area where the action happens.
2. Sprite – Characters or objects that move.
3. Backdrop – Background image of the stage.
4. Sprite List – Shows all sprites.
5. Blocks Tab – Categories of blocks (Motion, Looks, Sound, etc.).
6. Scripts Area – Workspace for blocks.
7. Costumes Tab – Change sprite appearance.
8. Sounds Tab – Add sounds and music.
9. Sprite Info – Name, size, position, direction.
10. Toolbar – Save, open, tutorials.
3.3 Paint Editor
• Used to draw or edit sprites and backdrops.
• Tools: shapes, colors, eraser, fill.
• Set center point (pivot) for rotation.
3.4 Arithmetic Operators and Functions
In Scratch, arithmetic operators are blocks found in the Operators
category (green blocks). They allow you to perform math operations
like addition, subtraction, multiplication, and division.
Common Arithmetic Operators in Scratch
● ( + ) → Addition
● ( - ) → Subtraction
● ( * ) → Multiplication
● ( / ) → Division
Example: Sum of Two Numbers in Scratch
Code (Block Layout)
when green flag clicked
ask [Enter first number:] and wait
set [num1 v] to (answer)
ask [Enter second number:] and wait
set [num2 v] to (answer)
set [sum v] to ((num1) + (num2))
say (sum)
3.5 Data Types in Scratch
1. Boolean – True/False (Switch ON/OFF).
2. Number – Integers/decimals (Score, Timer, Voltage).
3. String – Text (Names, messages).
1. Numbers
● Whole numbers or decimals.
● Used in math, movement, size, rotation, etc.
Example (text code form):
when green flag clicked
set [score v] to (0)
change [score v] by (1)
say (join [Your score is ] (score))
2. Strings (Text)
● Letters, words, or sentences.
● Used in say, ask, or join blocks.
Example:
when green flag clicked
ask [What is your name?] and wait
say (join [Hello, ] (answer))
3. Booleans (True/False)
● Appear as hexagon-shaped blocks.
● Used for conditions in if, repeat until, or loops.
Example:
when green flag clicked
if <(score) > (10)> then
say [You win!]
else
say [Keep trying!]
end
4. Lists (Arrays)
● Collections of items (numbers or text).
● Useful for storing multiple values.
Example:
when green flag clicked
delete all of [Names v]
add [Alice] to [Names v]
add [Bob] to [Names v]
say (item (1) of [Names v]) // will say "Alice"
5. Variables
● Can hold numbers or strings (Scratch doesn’t force a type).
● Example: score, name, timer.
when green flag clicked
set [name v] to [Alex]
set [score v] to (100)
say (join (name) (join [ has score ] (score)))
In short:
● Number → 5, 3.14, -2
● String → "Hello", "Scratch"
● Boolean → <touching color [#red]?>
● List → [1, 2, 3] or ["cat", "dog", "mouse"]
3.6 Variables
• Variable = storage to keep values.
• Creating a variable: Variables → Make a variable → Name it.
• Scope: Global (all sprites) or Local (this sprite only).
• Uses: store score, time, speed, voltage, etc
✨ How to Make a Variable
1.Go to the Variables category.
2.Click Make a Variable.
3.Give it a name (e.g., score, name).
4.Scratch creates blocks like:
○ set [variable v] to (value)
○ change [variable v] by (value)
○ (variable) (reporter block)
📝 Example Code (text form)
🎮 Score Counter
when green flag clicked
set [score v] to (0) // reset score at
start
forever
if <key [space v] pressed?> then
change [score v] by (1) // add 1 each
time space is pressed
say (join [Score: ] (score))
end
end
Note:
● set [score v] to (0) → initializes the variable.
● change [score v] by (1) → updates the value.
● (score) → retrieves and uses the value.
💬 Storing a Name
when green flag clicked
ask [What is your name?] and wait
set [playerName v] to (answer)
say (join [Hello, ] (playerName))
Note:
● Variables can also hold text.
● Here, playerName stores the user’s input.