Units — Computer Education — Class 8
  1. Unit 1ICT Fundamental
  2. Unit 2Digital Skills
  3. Unit 3Algorithmic Thinking and Problem Solving
  4. Unit 4Programming
  5. Unit 5Digital Citizenship
  6. Unit 6Entrepreneurship

Unit 4: Programming

Read the complete lesson, check the fully solved exercises, then test yourself with the MCQs quiz. Teachers get a complete guide with this unit.

Sindh Textbook Board50 MCQs5 Practice Sets

Computer Education — Class 8 · Unit 4 · Printed pages 92–121

Source: The Textbook of Computer Education for Class VIII, Sindh Textbook Board, Jamshoro.

About this source

Textbook text is reproduced for free educational study. All solutions, explanations, practice questions, diagrams and teacher's guides are original work by 100MCQs. 100MCQs is an independent site and is not affiliated with or endorsed by the Sindh Textbook Board. Read our Disclaimer.

📖 Lesson — Programming

Below is the complete lesson of Unit 4 from the textbook (printed pages 92–121), in the book's own order. Read it fully — important words are bold. After every part you will find two word boxes: 📚 Book Vocabulary (the book's own words, marked ⭐) and 🌱 Extra Help Words. Where the book prints something that does not work as printed, a note keeps the book's words and gives the checked correction openly. Every program in this unit has been traced by hand (inputs → steps → outputs) before being taught.

Part 1 — What this chapter teaches: the Student Learning Outcomes and 4.1 Introduction (printed pp 92–93)

The chapter opens with its Student Learning Outcomes (printed p 92). By the end of this unit, students will be able to:

  • Understand general control structures and their uses (sequence, loops, and conditions).
  • Use simple and nested loops in computer programs.
  • Tell the difference between 'repeat', 'forever', and 'repeat until' loops.
  • Apply simple as well as nested conditions in computer programs.
  • Differentiate between if and if else conditions.
  • Discuss the concept of functions in a computer program.
  • Use simple functions in a computer program.
  • Discuss the concept of cloning in a computer program.
  • Design high-level games like tic-tac-toe, maze with multiple levels, etc. (Group Project).
NOTE (printed p 92): the last outcome names tic-tac-toe, but the chapter body develops only the two maze games (Parts 14–15) — no tic-tac-toe project is printed in this chapter. Learn the outcomes for the topics the chapter actually teaches.

4.1 Introduction. This chapter takes you beyond the basics: you will use intermediate constructs — functions, cloning and conditional movement — and learn them by building mini-games in a visual programming tool, Scratch.

🌱 Extra Help Words — Words in this part

instruction — One single step that tells the computer what to do; a program is a list of instructions in a careful order.

Part 2 — 4.2 Visual versus Textual Programming (printed p 93)

Programs can be written in two ways. In textual programming you type code in a written language. In visual programming you drag picture blocks and join them together. The book's Figure 4.1 shows the same program — adding the numbers 0 to 9 into a sum — in both styles. The Java (textual) version, as printed:

int i=0;
int sum=0;
for (i=0;i<10;i++) {
    sum = sum + i;
}

The Scratch (visual) version of the same program is built from blocks:

set [i] to (0)
set [sum] to (0)
repeat (10)
    change [sum] by (i)
    change [i] by (1)

Both versions do exactly the same work: start i and sum at 0, then ten times add i to the sum and increase i by 1.

4.2.1 Difference Between Visual and Textual Programming. The book's comparison table compares the two styles on four points:

PointVisual programmingTextual programming
RepresentationPicture blocks that are dragged and joinedTyped code in a written language
EaseEasier to start; blocks fit only where they make senseNeeds exact typing and syntax
AudienceBeginners and studentsProgrammers writing larger programs
ExamplesScratchJava

📚 Book Vocabulary — Words in this part

visual programming — Making programs by dragging and joining picture blocks instead of typing code. The book contrasts it with textual programming (§4.2, printed p 93). ⭐Book word

textual programming — Making programs by typing code in a written language, such as the Java code shown beside the Scratch blocks in Figure 4.1 (§4.2, printed p 93). ⭐Book word

🌱 Extra Help Words — Words in this part

block palette — The list of block categories on the left of the Scratch editor — Motion, Looks, Sound, Events, Control, Sensing, Operators, Variables and My Blocks.

Part 3 — The building blocks, and 4.3 Sequential Statements (printed p 94)

Before §4.3, the book introduces the three building blocks from which Scratch programs are made: Sequence (blocks in order), Repetitive (loops that repeat blocks) and Conditional (blocks that run only when a condition is true). This chapter studies each of them in turn.

4.3 Sequential Statements. In a sequence, the blocks run one after another, in the order they are stacked. The book's worked example:

when [green flag] clicked
move (10) steps
say (Hello!) for (2) seconds

How it works: (1) the program starts when the green flag is clicked; (2) the sprite moves 10 steps forward; (3) the sprite says "Hello!" for 2 seconds. Prose and blocks agree exactly in this example.

📚 Book Vocabulary — Words in this part

sequence — One of the three basic building blocks of programs: blocks run one after another, in order, from top to bottom (§4.3, printed p 94). ⭐Book word

🌱 Extra Help Words — Words in this part

event — Something that starts a script, such as clicking the green flag or pressing a key.

Part 4 — 4.4 Conditional Statements and 4.4.1 if-then (printed pp 95–96)

4.4 Conditional Statements. A conditional statement runs blocks only when a condition is true. The book's "Remember" picture shows the Control palette blocks this chapter uses: wait 1 seconds, repeat 10, forever, if-then and if-then-else.

4.4.1 if-then. The book's example moves the sprite Giga with the arrow keys. The blocks of Figure 4.2(a), exactly as printed:

when [green flag] clicked
if <key (right arrow) pressed?> then
    move (100) steps
if <key (left arrow) pressed?> then
    move (-100) steps

The flow diagrams of Figure 4.2(b) say the same thing in picture form: Start → decision "Right Arrow Key Press" → True → "Move 100 Steps forward" → End; and Start → "Left Arrow Key Press" → True → "Move 100 Steps backward" → End.

Textbook correction (printed p 96): the prose sentence on this page says the code "moves Giga 10 steps to the right … and 10 steps back". That sentence is wrong: the blocks of Figure 4.2(a) and both flow diagrams of Figure 4.2(b) all use 100 steps. Learn the example as the blocks show it — 100 steps each way. (The genuine 10-step example is the sequence example of §4.3 on printed p 94.)

📚 Book Vocabulary — Words in this part

sprite — A character or object on the Scratch stage that carries scripts and can move, speak and change look — for example Giga in this chapter. ⭐Book word

conditional statement — A statement that runs its blocks only when a condition is true; the book builds programs from sequence, repetitive and conditional building blocks (§4.4, printed p 95). ⭐Book word

if-then — A Control block that runs the blocks inside it only if its condition is true; if the condition is false, nothing inside runs (§4.4.1, printed p 96). ⭐Book word

Part 5 — Making a maze sprite stop at walls: Figures 4.2(c) and 4.2(d) (printed pp 97–98)

The book now develops the if-then idea towards a maze game. Figure 4.2(c) moves a sprite in a maze with a key-press script:

when (right arrow) key pressed
change x by (5)

Figure 4.2(d) adds wall collision. After moving, the sprite checks whether it is touching the wall colour (blue); if it is, it moves the same distance back:

when (right arrow) key pressed
change x by (5)
if <touching color (blue)?> then
    change x by (-5)

Trace: press the right-arrow key away from any wall → the sprite moves +5 and the touching test is false, so it stays 5 steps further right. Press it against a blue wall → the sprite moves +5, the test becomes true, and it moves −5: net movement 0, so it looks as if the wall has stopped it. This bounce-back trick returns in both maze games (Parts 14–15).

Part 6 — 4.4.2 if-then-else: the Even–Odd Number Program (printed pp 98–100)

An if-then-else block has two branches: one for true, one for false, and exactly one of them always runs. The book builds a complete program that asks for a number and reports whether it is even or odd, in five steps:

  • Step 1. Take input with the ask block (Sensing) and store it in a new variable named Number (Variables → Make a Variable).
  • Step 2. The starting script:
when [green flag] clicked
set [Number] to (0)
ask (What's your number?) and wait
set [Number] to (answer)
  • Step 3. Use the mod operator (Operators) to check whether the number divided by 2 leaves a remainder of 0.
  • Step 4. The completed decision block:
if <(Number) mod (2) = (0)> then
    say (The number is Even) for (2) seconds
else
    say (The number is Odd) for (2) seconds
  • Step 5. Steps 2 and 4 together are the finished program. Traced sample runs (as printed): input 15 → 15 mod 2 = 1, so the else branch says "The number is Odd"; the book's other pictured run gives "The number is Even".
Textbook correction (printed p 99): the intermediate picture in Step 3 shows the block as (Number) mod (0) = (0) — a divisor of 0. Dividing by zero has no remainder, so that pictured block cannot work. The book's own Step 3 prose says "divided by 2", and the finished program in Steps 4–5 correctly uses mod (2). Learn the corrected mod-2 logic shown above; the mod-0 picture is a printing defect, not a program you should copy.
NOTE (printed pp 98–100): the book's pictured blocks contain spelling slips — the ask block is pictured once as "What's your name?" and elsewhere as "What's your numer?", and the say blocks read "The Numeber is Even/Odd". These are print slips in the screenshots only; the logic is unaffected. The listings above use the corrected spellings.

📚 Book Vocabulary — Words in this part

if-then-else — A Control block with two branches: the first runs if the condition is true, the second (else) runs if it is false (§4.4.2, printed pp 98–100). ⭐Book word

mod operator — The Operators block that gives the remainder when one number is divided by another; (Number) mod (2) tests whether a number is even (§4.4.2, printed p 99). ⭐Book word

🌱 Extra Help Words — Words in this part

variable — A named store for a value that can change while the program runs, such as Number, score or counter.

remainder — What is left over after a division: 15 divided by 2 leaves remainder 1, so 15 mod 2 = 1.

Part 7 — 4.4.3 if versus if-else, and 4.4.4 Nested if-then-else (printed pp 100–101)

4.4.3 Difference Between if and if else condition. The book's table compares them on three points:

Pointif-thenif-then-else
Condition outcomesOnly the true outcome has blocksBoth outcomes have blocks
Action for falseNothing runs; the program moves onThe else branch runs
UsageWhen an action is needed only if the condition is trueWhen a different action is needed when the condition is false

4.4.4 Nested if-then-else statement. When an if is placed inside another if, the conditions are nested: the inner condition is checked only after the outer one. The book's scenario (prose, printed p 101) is a score message:

  • If the score is 80 or more, say "Great job!"
  • Else, if the score is between 50 and 79, say "Good effort!"
  • Else, say "You need more practice!"

The blocks printed in Figure 4.3 are:

if <(score) > (80)> then
    say (Great job!)
else
    if <(score) > (50) or (score) < (79)> then
        say (Good effort!)
    else
        say (You need more practice!)
Textbook correction (printed p 101) — the printed blocks do NOT do what the book's own scenario says. Tracing the printed blocks by hand gives:
ScorePrinted blocks sayThe book's scenario intends
49"Good effort!" ✗"You need more practice!"
50"Good effort!" ✓ (but only because of the OR)"Good effort!"
79"Good effort!" ✓"Good effort!"
80"Good effort!" ✗"Great job!"
Two defects cause this. (1) The outer block tests score > 80, but the scenario says "80 or more" — so 80 itself never reaches "Great job!". (2) The inner test uses or instead of and: for every possible score, either "score > 50" or "score < 79" is true, so the inner condition is always true and the innermost else — "You need more practice!" — can never run. Learn the corrected version below, and never use the printed logic to judge a score.

The corrected blocks (whole-number scores, so "> 79" means 80 or more, and "> 49" means 50 or more):

if <(score) > (79)> then
    say (Great job!)
else
    if <(score) > (49)> then
        say (Good effort!)
    else
        say (You need more practice!)

Trace of the corrected blocks: 49 → not > 79, not > 49 → "You need more practice!" ✓ · 50 → "Good effort!" ✓ · 79 → "Good effort!" ✓ · 80 → "Great job!" ✓. All four boundaries now match the book's stated bands.

📚 Book Vocabulary — Words in this part

nested if-then-else — An if-then or if-then-else placed inside another if, so a second condition is checked only after the first one (§4.4.4, printed p 101). ⭐Book word

🌱 Extra Help Words — Words in this part

branch — One of the paths a conditional block can take — the 'then' path or the 'else' path.

Part 8 — Activity: is the number positive or negative — and even or odd? (printed pp 101–104)

The Activity box on printed p 101 sets a harder task: identify whether a given number is positive or negative, and (for the numbers it can) whether it is even or odd. The book builds it in six steps, nesting the Even–Odd block of Part 6 inside a new outer condition:

  • Steps 1 and 3. The same start as the Even–Odd program: ask for a number and store it in the variable Number.
  • Steps 2 and 4. The first question — positive or negative — is the outer condition. The even/odd check can only be made if the outer condition is true. The skeleton:
if <(Number) > (0)> then
    if <(Number) mod (2) = (0)> then
        say (The number is Even) for (2) seconds
    else
        say (The number is Odd) for (2) seconds
else
    say (The number is negative or zero.) for (2) seconds
  • Step 5. The outer else branch (above) covers everything that is not greater than 0 with the single message "The number is negative or zero."
  • Step 6. Run and verify. Printed sample runs: input 15 → "The number is Odd"; input −2 → "The number is negative or zero."
NOTE — read the printed program's scope carefully (printed pp 102–104): as printed, this program gives an even/odd answer only for positive numbers, because the mod-2 check is nested inside the (Number) > (0) branch. A negative number — even one like −2, which really is even — never receives a parity verdict. And zero is grouped together with the negatives in the message "negative or zero": the program cannot tell you which of the two you entered. Zero itself is neither positive nor negative. These are limits of the printed design, kept visible here so you learn the program exactly as it behaves.

🌱 Extra Help Words — Words in this part

trace (dry run) — Following a program's blocks by hand, writing down the values step by step, to check what it will do before running it.

Part 9 — 4.5 Loops and 4.5.1 Types of Loops (printed pp 104–105)

4.5 Loop (Repetitive Statements). A loop repeats a set of blocks. In Figure 4.4 a forever loop makes a sprite meow again and again:

when [green flag] clicked
forever
    wait (1) seconds
    say (Meow)
    start sound (Meow)

4.5.1 Types of Loops. Scratch has three loop blocks, and the book shows the same walking program built with each of them:

(a) repeat — runs its blocks a fixed number of times (Figure 4.5(a)):

when [green flag] clicked
point in direction (90)
repeat (10)
    next costume
    move (10) steps
    wait (1) seconds
    turn clockwise (15) degrees

(b) repeat until — repeats until its condition becomes true; here a counter variable counts the passes (Figure 4.5(b)):

when [green flag] clicked
point in direction (90)
set [counter] to (0)
repeat until <(counter) = (10)>
    change [counter] by (1)
    next costume
    move (10) steps
    wait (1) seconds
    turn clockwise (15) degrees

(c) forever — never stops by itself; Figure 4.5(c) guards the actions with an if so they happen only while the counter is below 10:

when [green flag] clicked
point in direction (90)
set [counter] to (0)
forever
    if <(counter) < (10)> then
        change [counter] by (1)
        next costume
        move (10) steps
        wait (1) seconds
        turn clockwise (15) degrees
Textbook correction (printed p 105): the prose claims that if the counter in Figure 4.5(b) "is mistakenly set to −1, the code will not work as expected, and the loop will run infinite time." Trace it: starting at −1 and adding 1 each pass, the counter still reaches 10 — after 11 passes — and the loop stops. It runs one extra pass, not forever. (A loop truly runs forever only if its stopping value can never be reached, for example if the counter moved away from the target.)

📚 Book Vocabulary — Words in this part

loop — A structure that repeats a set of blocks; the book's three loop blocks are repeat, repeat until and forever (§4.5, printed p 104). ⭐Book word

repeat — A loop block that runs its blocks a fixed number of times, e.g. repeat (10) (§4.5.1, printed p 105). ⭐Book word

repeat until — A loop block that repeats its blocks until its condition becomes true, and then stops (§4.5.1, printed p 105). ⭐Book word

forever — A loop block that repeats its blocks without end, until the project is stopped (§4.5.1, printed p 105). ⭐Book word

🌱 Extra Help Words — Words in this part

iteration — One complete run through the blocks inside a loop; a repeat (10) loop has 10 iterations.

Part 10 — 4.6 Nested Loops: Giga walks through the backdrops (printed pp 106–107)

A nested loop is a loop inside a loop. The book's program makes the sprite Giga walk across at least three backdrops: choose the Giga sprite and the backdrops, send Giga to the start, then run a repeat until loop (counting to 4) inside an outer repeat (10) loop; after each inner loop finishes, the backdrop switches. The complete code (printed p 107):

when [green flag] clicked
go to x: (-145) y: (-77)
repeat (10)
    set [counter] to (0)
    repeat until <(counter) = (4)>
        change [counter] by (1)
        next costume
        move (10) steps
        wait (1) seconds
    wait (0.1) seconds
    switch backdrop to (next backdrop)

Trace: the counter is reset to 0 at the start of every outer round, so the inner loop always runs exactly 4 times — Giga changes costume and moves 10 steps each time (40 steps per round) — and then the backdrop switches once. Over the 10 outer rounds the backdrop switches 10 times. The book's output pictures show Giga on three backdrops: a school building, a desert and a beach.

📚 Book Vocabulary — Words in this part

nested loop — A loop placed inside another loop; in §4.6 a repeat until loop runs inside a repeat (10) loop (printed pp 106–107). ⭐Book word

counter — A variable used to count how many times a loop has run; the loop programs of §4.5.1 and §4.6 use a counter variable. ⭐Book word

backdrop — The background picture of the stage; a program can switch backdrops, as the Giga walking program does after every outer loop round (§4.6, printed pp 106–107). ⭐Book word

Part 11 — 4.7 Functions and 4.7.1 Built-in Functions in Scratch (printed pp 107–109)

4.7 Functions in Scratch. A function is a ready-made or self-made piece of code that does one job. Scratch functions come in two kinds: built-in functions, which Scratch already provides, and custom functions, which you define yourself (Part 12).

4.7.1 Built-in functions. The book presents these genuine Scratch operators:

  • pick random — chooses a whole number at random inside a range; the book's figure builds set counter to (pick random (1) to (10)).
  • abs — the absolute value of a number, its distance from zero: abs of −9 is 9, and the book's figure shows (abs) of (−3) giving 3.
  • join — joins two pieces of text (or text and numbers) into one: join (apple) (banana) gives "applebanana". It lives in the Operators category.
Textbook correction (printed p 108): the prose says "the absolute value of −9 is 9, as shown in the figure" — but the figure actually shows (abs) of (−3) giving 3. Both answers are correct examples of abs; only the cross-reference is wrong. One more precision the book leaves out: abs gives the non-negative value — abs(0) = 0, and zero is not a positive number.

Rounding. The ( ) of ( ) operator block also rounds numbers. The book's table (printed p 109):

FunctionWhat it doesPrinted example
roundRounds to the nearest whole numberround (45.5) → 46
floorAlways rounds a number down(floor) of (45.8) → 45
ceilingAlways rounds a number up(ceiling) of (45.2) → 46

All three printed examples are correct. The book describes round as "rounds a number up if the decimal is greater than 4" — the precise rule is: look at the fractional part; if it is 0.5 or more, round up, otherwise round down (that is why 45.5 → 46).

The book then prints a table of "additional functions available in Scratch": sqrt( ), type( ), pow( ), max( ), bool( ), format( ) and help( ).

Textbook correction (printed p 109) — read this table honestly: of the seven entries, only sqrt( ) is a genuine Scratch operator — it is one of the choices in the ( ) of ( ) block's dropdown in the Operators palette (the same dropdown that offers abs, floor, ceiling, and also 10 ^ and e ^ for powers). The other six — type( ), pow( ), max( ), bool( ), format( ) and help( ) — are Python built-in functions; Scratch has no blocks with these names, and you cannot use them in a Scratch project. The book's table has copied them into the wrong language. This matters for the Exercise: question v of Exercise Block 1 is built on this table — it is solved in the Solved Exercise tab exactly as the book intends, with this warning attached.

📚 Book Vocabulary — Words in this part

function — A named piece of code that performs a task and can be reused; the book divides Scratch functions into built-in functions and custom functions (§4.7, printed p 107). ⭐Book word

built-in function — A function Scratch already provides, ready to use — for example pick random, abs and join (§4.7.1, printed pp 108–109). ⭐Book word

absolute value (abs) — The distance of a number from zero, given by the (abs) operator: abs of −3 is 3, and abs of 0 is 0 (§4.7.1, printed p 108). ⭐Book word

round — An operator in the ( ) of ( ) block that rounds a number to the nearest whole number; round of 45.5 is 46 (§4.7.1, printed p 109). ⭐Book word

floor — An operator that always rounds a number down to the whole number below it; floor of 45.8 is 45 (§4.7.1, printed p 109). ⭐Book word

ceiling — An operator that always rounds a number up to the whole number above it; ceiling of 45.2 is 46 (§4.7.1, printed p 109). ⭐Book word

Part 12 — 4.7.2 Custom Functions: the Calculate Area block (printed p 110)

In the My Blocks palette, "Make a Block" lets you define your own block (Figure 4.6 shows the dialog). The book defines a block named Calculate Area with two inputs, length and width. Its definition (Figure 4.7):

define Calculate Area (length) (width)
set [area] to ((length) * (width))

The main script asks for the two inputs and then calls the block:

when [green flag] clicked
ask (length) and wait
set [length] to (answer)
ask (width) and wait
set [width] to (answer)
Calculate Area (length) (width)
say (area)

Worked trace: if the user enters length 4 and width 2, the block sets area to 4 × 2 = 8 and the sprite says 8 — the output pictured in the book (the book does not print which inputs produced its pictured 8, but 4 × 2 shows the working). Once defined, the same block can be reused for any rectangle without rebuilding it.

📚 Book Vocabulary — Words in this part

custom block (My Blocks) — A block you define yourself with Make a Block in the My Blocks palette, for example the Calculate Area block with inputs length and width (§4.7.2, printed p 110). ⭐Book word

🌱 Extra Help Words — Words in this part

argument — A value passed into a custom block when it is called, such as the 4 and 2 passed as length and width to Calculate Area.

Part 13 — 4.8 Cloning a Sprite (printed p 111)

Cloning makes copies of a sprite while the program runs. The book's example fills the sky with balloons. Two scripts work together (Figure 4.8(a)). The original sprite's script hides itself and keeps creating clones at random positions:

when [green flag] clicked
hide
forever
    go to x: (pick random (-250) to (250)) y: (-200)
    next costume
    create clone of (myself)
    wait (0.5) seconds

Each clone runs its own script when it starts: it shows itself, floats upward while shrinking, and then deletes itself:

when I start as a clone
show
repeat (50)
    point in direction (pick random (80) to (100))
    change y by (10)
    change size by (-2)
wait (2) seconds
delete this clone

Figure 4.8(b) shows the result: many balloons floating over a field backdrop. Because every clone deletes itself at the end of its script, finished balloons disappear instead of piling up forever.

📚 Book Vocabulary — Words in this part

cloning — Making copies of a sprite while the program runs; each copy (clone) runs the script under 'when I start as a clone' (§4.8, printed p 111). ⭐Book word

Part 14 — 4.9.1 The Simple Maze Game (printed pp 112–113)

4.9 Game Design with Scratch puts everything together. In the Simple Maze Game the player guides a sprite through a maze of blue walls (Figure 4.9: blue walls, a red start dot at the top-left, and a small green goal square at the bottom-right) without touching the walls. The book's six steps:

  • Step 1 — Create the maze: draw or choose a backdrop whose walls form the path.
  • Step 2 — Add a sprite: the player, for example a ball or a character.
  • Step 3 — Set up movement (on the player sprite):
when [green flag] clicked
go to x: (-205) y: (147)

when (up arrow) key pressed
point in direction (0)
move (10) steps

when (down arrow) key pressed
point in direction (180)
move (10) steps

when (right arrow) key pressed
point in direction (90)
move (10) steps

when (left arrow) key pressed
point in direction (-90)
move (10) steps
  • Step 4 — Add wall collision (same sprite): a forever loop watches for the wall colour and pushes the sprite back the same distance it just moved:
when [green flag] clicked
forever
    if <touching color (blue)?> then
        move (-10) steps
  • Step 5 — Set the goal: add a second sprite (for example a star) as the goal, and put this script on the goal sprite:
when [green flag] clicked
forever
    if <touching (Ball)?> then
        say (You win!)
  • Step 6 — Execute your game: run it and check that the sprite moves correctly and the goal works.
startgoal

The simple maze in schematic form (100MCQs drawing, from the book's Figure 4.9 description): blue walls, red start at the top-left, green goal at the bottom-right.

NOTE (printed p 113): two wordings on this page do not match the code. Step 4's heading says "Make the sprite stop if it touches the walls", while the printed comment beside the blocks says the ball "bounces back" — the code (move −10 steps) actually reverses the sprite along its direction, so "bounces back" is the better description. Also, the goal script tests touching (Ball)? — it works only if your player sprite is actually named "Ball"; if you add "a ball or character" with another name (Step 2), choose that name in the touching block.

📚 Book Vocabulary — Words in this part

collision — When a sprite touches a wall or another sprite; the maze games detect it with touching color / touching blocks and make the sprite bounce back (§4.9.1, printed p 113). ⭐Book word

🌱 Extra Help Words — Words in this part

coordinates (x, y) — Two numbers that give an exact position on the stage: x for left–right, y for up–down.

Part 15 — 4.9.2 The Advance Maze Game: many levels (printed pp 114–119)

The book's second project (its heading spells it "Advance Maze Game") is a multi-level maze. The project files are obtained from a download link printed in the book (inventwithscratch.com) — your teacher can fetch them for the class. Three sprites work together: the Cat (the player, "Sprite1"), the maze itself as a sprite, and an Apple marking the exit at the top of the maze; the Cat enters at the bottom.

Step 2 — the Cat's skeleton script. The Cat's code is a forever loop holding five if blocks: four check the arrow keys, and the fifth checks the exit Apple. The skeleton (printed p 115):

when [green flag] clicked
set size to (10) %
go to x: (10) y: (-170)
erase all
forever
    if <> then  ①
    if <> then  ②
    if <> then  ③
    if <> then  ④
    if <> then  ⑤

The green flag starts the game, the Cat shrinks to 10% and goes to the starting point x: 10, y: −170, and erase all (a Pen block) clears any pen drawings. Each numbered if is now filled in:

Block ① — up arrow (printed p 116):

if <key (up arrow) pressed?> then
    change y by (4)
    next costume
    if <touching (maze)?> then
        change y by (-4)
    else
        change y by (-4)
        change y by (4)

Block ② — down arrow (printed p 116):

if <key (down arrow) pressed?> then
    change y by (-4)
    next costume
    if <touching (maze)?> then
        change y by (4)
    else
        change y by (4)
        change y by (-4)

Block ③ — right arrow (printed p 117):

if <key (right arrow) pressed?> then
    change x by (4)
    next costume
    if <touching (maze)?> then
        change x by (-4)
    else
        change x by (-4)
        change x by (4)

Block ④ — left arrow (printed p 117):

if <key (left arrow) pressed?> then
    change x by (-4)
    next costume
    if <touching (maze)?> then
        change x by (4)
    else
        change x by (4)
        change x by (-4)

How each movement block behaves (traced): the Cat first moves 4 points. If it is then touching the maze, it moves 4 points back — net movement 0, the bounce-back. If it is not touching, the else branch moves −4 then +4 (net 0 extra), so the original 4-point move stands. The else pair is redundant but harmless.

Textbook corrections (printed pp 116–117): (1) The prose under all four blocks says the sprite will move "1 point" — the blocks all move 4 points; follow the blocks. (2) The prose pictures the sensing block as touching (mouse-pointer)? while telling you to select "maze" — the working code uses touching (maze)?; choosing mouse-pointer would test the mouse, not the walls. (3) The left-arrow prose says the sprite moves "−4 points right" — a slip; change x by (−4) moves it left, as the blocks show.

Block ⑤ — reaching the Apple (printed p 118):

if <touching (Apple)?> then
    say (You Win!) for (1) seconds
    go to x: (10) y: (-170)
    broadcast (next maze)
    erase all

The broadcast block (Events palette) sends the message "next maze" to the maze sprite, whose receiver script changes the maze — the book says this "adds up the level and difficulty in the game":

when I receive (next maze)
next costume

Step 3 — the maze sprite's own code (printed p 119). At the green flag it picks a maze costume at random (the side panel says there are 100 maze backgrounds for levels and difficulty) and centres itself:

when [green flag] clicked
switch costume to (pick random (1) to (100))
go to x: (0) y: (0)

when I receive (next maze)
next costume
NOTE (printed p 119): the book's Step 4 heading, "Set the Goal:", is printed with nothing under it — the goal content follows as Step 5 ("We are using apple for finishing the game") and Step 6 (the Apple code below). Nothing is missing from the project itself; only the heading is empty.

Step 6 — the Apple sprite's code:

when [green flag] clicked
set size to (25) %
go to x: (-10) y: (170)

Steps 7–8 — execute the game: with all the code in place, press the green flag and play. Two design facts to notice while you play: the Cat restarts at the same point (10, −170) on every level, and the Apple stays at the same place (−10, 170) on every level even though the maze picture changes; and the maze is a sprite carrying scripts (that is why touching (maze)? works), although the prose sometimes calls it a background.

📚 Book Vocabulary — Words in this part

broadcast — An Events message sent by one script and received by others; in the Advance Maze Game the Cat broadcasts (next maze) to change the level (§4.9.2, printed p 118). ⭐Book word

costume — One of the looks of a sprite; 'next costume' changes the look. The maze sprite changes costume to bring in a new maze (§4.9.2, printed pp 118–119). ⭐Book word

🌱 Extra Help Words — Words in this part

stage — The area of the Scratch window where the sprites perform and the game is seen.

level — One stage of a game; finishing it takes the player to the next, usually harder, stage.

Part 16 — Summary of the chapter (printed p 120)

The book's summary collects the chapter in nine points:

  • Sequence — blocks execute one after another in order.
  • Conditional statement — runs blocks only when a condition holds.
  • if statement — one branch, taken when the condition is true.
  • if-else statement — two branches, one for true and one for false.
  • Loop — repeats a set of blocks.
  • repeat loop — repeats 'x' times.
  • repeat until loop — repeats until its condition becomes true.
  • forever loop — repeats without end.
  • Function — a named, reusable piece of code that performs a task.

That completes the chapter. Its Exercise is short — only 8 questions — and every one is solved in the next tab. One honest note: no Scratch editor was available while this page was written, so every program above has been verified by careful hand-tracing (inputs → steps → outputs), and running the projects in Scratch remains a classroom step.

Help us improve this page. Spotted a mistake, or something that is not clear? Email us at [email protected] — every report helps the next student.