Events, Conditions and Choices in Programs

Make block programs that react when something happens and choose what to do. You learn how events such as key presses, clicks and messages start scripts, how conditions are true or false, and how if-then and if-then-else pick which blocks run. You compare numbers and typed answers, choose between more than two options, build your own quiz and a simple game, and test every branch to find and fix bugs.

Grade 2, Grade 3Lesson 3 of 10 in Computing and Coding for Ages 7 to 11 Course

What you will learn

  1. Find out what events are, then build scripts that start when you press a key, click a character, push a button or send a message. You also make several characters act at the same time.
    • Spot events and the actions they start
      Learn what an event is, find events in everyday life and in programs, and tell the event apart from the action it starts.
    • Build scripts that start with an event
      Plan what should happen and what makes it happen, then build event scripts, such as arrow keys that move a character, and try each event to see that it works.
    • Make several scripts and characters work at the same time
      Use one event to start several scripts at once, give each character its own scripts, send messages between characters and predict what a program will do before you run it.
  2. Learn what a condition is, then use if-then to do something only when a condition is true, and if-then-else to choose between two different actions.
    • Ask questions that are true or false
      Turn everyday questions into conditions, check whether they are true or false, and join two conditions with and, or and not.
    • Use if-then to do something only when a condition is true
      Build if-then blocks, follow them in a flowchart, and keep checking a condition inside a loop so your program notices when it becomes true.
    • Use if-then-else to choose between two actions
      Use if-then-else so your program does one thing when a condition is true and something different when it is false, and decide when you need else.
  3. Use greater than, less than and equal to so your program can decide by comparing numbers, sensor readings and typed answers, and choose between more than two options.
    • Compare numbers with greater than, less than and equal to
      Use the symbols >, < and = to compare numbers from answers, sensors and positions, and decide what should happen when the two numbers are equal.
    • Check a typed answer against the right answer
      Ask the player a question, compare what they type with the right answer using equal to, and write questions whose answers your program can check well.
    • Choose between more than two options
      Put one if-then-else inside another to pick one of three or more actions, and put the checks in an order that gives the right choice.
  4. Plan and build your own quiz and a simple game that use events, conditions and comparisons to react to the player.
    • Plan and build a quiz
      Plan your quiz questions, right answers and replies in a table or storyboard, then build it with ask blocks, comparisons and if-then-else.
    • Build a simple game with rules
      Write your game’s rules as if-then sentences, then build them with events for the controls and conditions that are checked again and again inside a loop.
  5. Plan tests that try every branch of your choices, find and fix bugs in events and conditions, and make your program clearer and shorter.
    • Test each branch of a choice
      Choose test inputs that make each condition true and false, try the numbers right on the limit, and record what you expected and what happened in a test table.
    • Find and fix bugs in events and choices
      Use a step-by-step way to find out why a program does the wrong thing, fix common bugs in events, conditions and comparisons, and test again after every fix.
    • Make your program clearer and shorter
      Check your program against the task, make it shorter and easier to read with else and loops, and improve it using feedback from other people.

Events and Conditions in Coding study guide

5 chapters

1

Make programs react when something happens

Your program can wait for a click, a key, or a message. You decide what each trigger starts and which character owns the actions. Begin with a signal game, then make controls and setup scripts. When several scripts start together, you can make a whole scene move and sound at once.

1.1 What starts the action?

Imagine playing a signal game with a friend. Agree on two rules: “When I clap, touch your nose.” “When I stamp, sit down.” Wait quietly, then try each signal. The clap starts one action. The stamp starts another.

Find the trigger

An event is something that happens that a program can notice. It might be a key press or a click. The event is the trigger: it starts the action. In “When I click the cat, it meows,” clicking is the event. Meowing is the action it starts.

A script can wait without doing anything. The blocks under when space key pressed wait for that key. Clicking a character does not start that script. You need to make its own event happen.

Events in a program

A script that reacts to an event begins with an event block. You might choose when start button clicked or when this character clicked. Attach the action blocks underneath it. They run in order, from top to bottom, when the event starts them.

For a clicking cat, build this small script:

when this character clicked
  play sound "meow"

Click the cat once and listen. The event block notices the click. Then the sound block runs. Look for the event block before predicting what any script will do.

What goes in and comes out?

An input is something going into the computer. An output is something it does that you can see or hear.

InputOutput
Press button A on a board.A heart appears on its lights.
Click a character.The character makes a sound.
Press an arrow key.A character moves.

Events can come from a keyboard, mouse, microphone, or programmable board. A board might notice a button press or a shake. Programs can also send messages that start other scripts. Those events come from inside the program.

To separate an event from an action, ask, “What happened first?” In “When the bell rings, line up,” the ringing comes first. Lining up is what the signal asks you to do.

Key Takeaways

  • An event triggers an action.
  • An event block starts the attached blocks in order.
  • An input goes into the computer; an output is something it does.
  • A program can make an event by sending a message.

1.2 Build a script for each control

Start with a sentence about your character: “When the space key is pressed, the bird flies up.” It tells you which trigger and which action you need. A plan of steps like this is an algorithm.

Choose, attach, try

Build an event script in four steps:

  1. Decide what should happen and what starts it.
  2. Choose the matching event block.
  3. Snap the action blocks underneath in the right order.
  4. Make the event happen and watch the result.

For “When the start button is clicked, the bird says ‘Hi!’,” choose the start event. Attach a say block with the text "Hi!" Click the start button to try it. A space-key script needs a separate event block.

Move left and right

Make two scripts on the character you want to move:

when right arrow key pressed
  change x by 10

when left arrow key pressed
  change x by -10

The x position tells you where the character is from left to right. Adding 10 moves right. Changing it by −10 moves left.

Press the right arrow three separate times. The script runs three times. Each press adds 10 steps, so the character moves 30 steps right. One press does not make it move forever. The script finishes after its move block.

Set up a fresh run

Put setup blocks under the start event:

when start button clicked
  go to starting spot
  show
  say "Ready!"

The character returns to its starting spot before saying "Ready!" This helps you try the same program again from the same place.

An event can also start a loop. Attach forever, then put next costume and wait 0.2 seconds inside it. The costumes keep changing after the single start click. The loop repeats the actions until you stop the program.

Check where the blocks belong

A loose action block will not run with the event. Drag it until it snaps into the script. Also check the selected character. A dog-click script belongs on the dog. A script on the cat that says when this character clicked reacts to the cat's clicks.

Test both arrow keys separately. If only one works, inspect that key's event, its attached blocks, and the character that owns it.

Key Takeaways

  • Plan the trigger and action before choosing blocks.
  • Snap actions onto the matching event block.
  • Each character owns its own scripts.
  • Repeated key presses run a short event script repeatedly.
  • A start event can set up a run or begin a loop.

1.3 Start several scripts together

A scene can have several things happening together. A fish swims while a crab follows your arrow keys. Each character has its own scripts. Another word for a character is object; some block languages call it a sprite.

One trigger, several scripts

If two scripts use the start-button event, the click starts both. One can make a cat walk while another plays music. Their actions can overlap in time.

Inside each script, blocks still run from top to bottom. Suppose a walking loop never ends. A music block placed after that loop is never reached. Put the music in another script with the same event so both jobs can begin.

A static object stays in one place. A rock, wall, or finish line can be static. It can still matter to the scene: a moving character might touch it.

Send a message

A program can make its own event by sending a message. Sending a message is also called broadcasting.

On the starter, build:

when start button clicked
  broadcast "start race"

On the dog, build:

when I receive "start race"
  move 10 steps

Give the horse a matching receive script. The dog and horse both react when the message is sent. Check that every receiver listens for the same message name. A receiver keeps waiting if no script ever sends its message.

Predict the timing

Read these two start-button scripts before you run them:

  • The owl says "Ready?" for 2 seconds.
  • The frog waits 2 seconds, then says "Go!"

Both scripts start at the click. For the first 2 seconds, the owl is speaking and the frog is waiting. After its wait, the frog speaks. The frog does not wait for the owl's whole script just because the owl appears first on your screen.

Watch for scripts that clash

Two scripts can try to move the same character at once. One might move it right while another moves it left. The character can wobble or seem stuck. Read all the scripts that start together. Check what each one changes before deciding that a single move block is broken.

Key Takeaways

  • One event can start several scripts at the same time.
  • Blocks within each script keep their own order.
  • A broadcast starts scripts listening for that message.
  • Static objects stay in one place but can affect game rules.
2

Make choices with if, then and else

A game needs to notice what is happening and choose its next action. You will turn everyday yes-or-no questions into conditions. Then you will trace the paths through if-then and if-then-else, and use loops to check again as the player moves. The place you attach each block matters.

2.1 Ask a yes-or-no question

Look around and ask, “Is there something blue near me?” Your answer is yes or no. A program uses questions like this to make choices.

A condition gives true or false when checked. Yes means true. No means false. “Is the car blue?” is a condition. “What color is the car?” asks for a color, so it is not a true-or-false condition.

Check at this moment

A condition's answer can change. “Is it raining?” might be false this morning and true this afternoon. A program gets the answer at the moment it checks.

Try an unplugged rule with friends: “If you are wearing red, stand up.” Each person checks their own clothes. Some stand; others stay seated. The rule stays the same, but the answers differ.

In an everyday if-then rule, the condition comes after if. The action comes after then: “If it is raining, then take an umbrella.”

Join conditions with and

And needs both parts to be true. “If it is Saturday and it is sunny, then go to the park.”

  • Sunny Saturday: both parts are true, so go.
  • Rainy Saturday: only one part is true, so do not go.
  • Sunny Monday: only one part is true, so do not go.

Check both parts before deciding about the joined condition.

Join conditions with or

Or needs at least one true part. Both parts being true also counts. “If it is your birthday or you finished your chores, then choose the movie.”

You can choose on your birthday. You can also choose after finishing your chores. If both happen, you still meet the rule. In programs, or does not mean “exactly one.”

Turn a condition around

Not flips the answer. If “It is raining” is true, “It is not raining” is false. If rain is false, not raining is true.

In many block languages, conditions have pointed ends. They fit the condition gap of an if block. Examples include touching edge?, key space pressed?, and answer = 56. Each gives a true-or-false answer when checked.

Key Takeaways

  • A condition gives true or false when checked.
  • A condition can give a different answer later.
  • And needs both parts to be true.
  • Or accepts one true part or both.
  • Not flips true and false.
  • The condition follows if; the action follows then.

2.2 Run an action only when it fits

Sometimes an action should happen only when a condition is true. A game might play a ding when you touch a coin. It should keep going quietly when you do not touch one.

Follow an if-then

Choosing blocks by checking a condition is called selection. You may also hear conditionals. An if-then block checks once when the program reaches it.

  • True: run the blocks inside.
  • False: skip the blocks inside.
  • Either way: carry on with the block after the if.

Try the rule “If it is raining, put on your raincoat. Walk to school.” On a rainy day, put on the coat, then walk. On a dry day, skip the coat and walk. The walk belongs after the choice, so it happens either way.

Put actions in the right place
if touching coin? then
  play sound "ding"
say "Keep going!"

Touching the coin makes the sound play. The say block runs whether or not you touched it. Move that block inside the if only if you want the message to depend on touching the coin too.

A flowchart shows these paths as a picture. Put the condition in a diamond. Label one arrow “yes” and lead it to the action. Label the other “no” and lead it around the action. Join both paths before the next shared step.

Keep checking during play

An if is not always watching. Put it directly under the start event, and it checks only at the start. If you reach the coin later, that finished check misses you.

Put the if inside a forever loop to check again and again:

when start button clicked
  forever
    if key up arrow pressed? then
      change y by 10

The loop keeps checking the key. Holding it down keeps moving the character up. Releasing it makes the condition false, so the move is skipped on later checks.

Stop repeating when a condition becomes true

A repeat-until loop uses a condition to stop. For repeat until touching edge?: move 5 steps, check the edge first. False means move, then check again. True means leave the loop and carry on. If the character already touches the edge at the start, the move inside runs zero times.

Key Takeaways

  • If-then runs its inside blocks only when the condition is true.
  • Blocks after the if run whichever path was taken.
  • An if checks once each time the program reaches it.
  • A forever loop repeats checks; repeat-until stops when its condition is true.

2.3 Give a different reply for each answer

A quiz needs two replies. A correct answer gets praise. A wrong answer gets help. If-then-else chooses between those two actions.

Trace the two branches

Each path through a choice is a branch. The then branch runs when the condition is true. The else branch runs when it is false. Each time the choice runs, exactly one branch runs.

ask "What is 7 × 8?" and wait
if answer = 56 then
  say "Correct!"
else
  say "Not quite. 7 × 8 = 56."

Follow an answer of 56. The answer matches 56, so the condition is true. Say "Correct!" and skip the else reply.

Now follow an answer of 54. The comparison is false. Skip "Correct!" and use the helpful else reply. The program does not run both replies in one visit to this choice.

Draw both paths

In a flowchart, put answer = 56? in a diamond. Draw a yes arrow to "Correct!" and a no arrow to the helpful reply. Join the paths before the next question. Whichever reply the player gets, the quiz can continue.

An if-then also has two paths. Its false path simply skips the inside action.

What you needBlock to choose
A ding only when touching a coinIf-then
Praise for right, help for wrongIf-then-else
Catch the value in the middle

Two separate ifs can leave a gap. Imagine checking temperature > 80 for "It's hot!" and temperature < 80 for "It's not hot." At exactly 80 °F, both checks are false. Neither message runs.

Use if temperature > 80 with an else reply instead. At 80 °F, greater than 80 is false. The else branch says "It's not hot." Every reading now gets one reply.

If a quiz praises wrong answers, inspect the branches. "Correct!" belongs inside then when the answer-equals check is true. A program can run without stopping yet still give the wrong reply. Try a right answer and a wrong one to check both places.

Key Takeaways

  • If-then-else runs then for true and else for false.
  • Exactly one branch runs each time this choice is reached.
  • Use else when the false case needs its own action.
  • Two separate comparisons can leave an equal value out.
  • Test both branches to catch swapped replies.
3

Compare numbers and answers to make decisions

Numbers help your program choose: a typed answer, a position, or a sensor reading can guide it. You will read comparison signs, check what happens at an exact limit, and ask before judging an answer. Once two-way choices make sense, you can join choices into a chain with three replies.

3.1 Choose the right comparison

A program can compare numbers to decide what happens next. A comparison gives true or false, so it can fill the condition gap in an if block.

Read the signs
SignMeaningExample
>Greater than12 is greater than 9.
<Less than3 is less than 7.
=Equal to10 is equal to 10.

The wide side faces the bigger number. Read 12 > 9 from left to right: “12 is greater than 9.” In code, answer = 56 checks whether the answer matches 56.

The numbers can come from typed answers, a timer, a character's position, or a sensor. A sensor notices something around it, such as light, and gives the program a reading.

Check the limit itself

Try this weather choice:

if temperature > 80 then
  say "It's hot!"
else
  say "It's not hot."

At 95 °F, the condition is true. At 60 °F, it is false. At exactly 80 °F, it is also false: equal is not greater.

Suppose your rule should include 80 as hot. Flip the question: if temperature < 80 gives "It's not hot," and else gives "It's hot!" Now 79 takes then, while 80 takes else. Decide where equality belongs before you build.

Compare shapes and positions

For a rectangle, compare its length and width. Equal side lengths make that rectangle a square. A 5-inch by 5-inch rectangle passes; a 5-inch by 3-inch rectangle does not.

In a race, a finish line can be at x position 200. Checking x position > 200 inside a forever loop notices when the character passes it. At exactly 200, that comparison is still false.

Read a changing sensor

On this example board, light readings run from 0 for dark to 255 for bright. Use a forever loop with if light level < 50: turn lights on in then and off in else. A reading of 20 turns them on. Readings of 50 and 200 turn them off.

Using light level = 50 would catch only that exact reading. A sensor could jump from 52 to 48 and miss it. A less-than check covers the dark readings on that side of the limit. To catch a reversed sign, read your check aloud: “Light level is less than 50.”

Key Takeaways

  • Comparisons give true or false.
  • The wide side of > or < faces the bigger number.
  • Equal values make both greater-than and less-than checks false.
  • Decide which branch should receive the boundary value.
  • Use a range comparison when a sensor might skip an exact reading.
  • Compare rectangle sides, positions, timers, or sensor readings.

3.2 Ask first, then check the answer

A quiz needs to wait for the player. The ask block shows a question and waits for typing and Enter. The answer block holds what the player typed most recently.

Build one question in order

Use this order each time:

  1. Ask the question and wait.
  2. Compare the answer with that question's right answer.
  3. Give the right-answer reply or the wrong-answer reply.

For a spider question, the script is:

ask "How many legs does a spider have? Type a number." and wait
if answer = 8 then
  say "Yes! Spiders have 8 legs."
else
  say "Not quite. Spiders have 8 legs."

Typing 8 makes the comparison true. Typing 6 makes it false. The comparison checks the answer, not the words of the question.

Check the newest answer

Suppose you ask a math question, then a spider question. The spider answer replaces the math answer in the answer block. Check the math answer before asking the spider question.

Checking before the ask block is another order bug. The program has not collected the new answer yet. It checks an older answer, or an empty one. Move ask before the matching if-then-else.

Tell the player what to type

A computer matches the answers you tell it to match. If you check for 8, the word "eight" does not match. If you check for "Paris," "Pari" does not match either. The player's idea can be right even when the typed text fails the check.

Choose clear questions with a simple typing rule. You can say "Type a number" or "Type yes or no." For a choice of answers, label them a, b, and c and ask the player to type a letter. Plan which letter the program should accept.

Make feedback useful

A wrong-answer reply can teach. "Not quite. Spiders have 8 legs" tells the player what to remember. A reply that says only "Wrong!" does not help them repair the mistake.

When you add another question, change both its question text and its comparison. Leaving the previous right answer in the new comparison makes the quiz judge the new question incorrectly.

Key Takeaways

  • Ask and wait before checking an answer.
  • The answer block keeps only the most recent answer.
  • Compare with the right answer for that question.
  • Tell players what form to type and give helpful feedback.

3.3 Choose one of three actions

Some rules need more than two actions. You might walk, ride a bike, or take a bus. Put a second if-then-else inside the first else to make an else-if chain.

Follow the checks in order
if distance < 2 miles then
  walk
else
  if distance < 5 miles then
    ride a bike
  else
    take the bus

Start at the top each time. If the first check is true, walk and skip the rest. If it is false, enter else and check the second condition. The last else catches the distances left over.

Trace 1 mile: less than 2 is true, so walk. Trace 2 miles: less than 2 is false, but less than 5 is true, so bike. At 4 miles, bike again. At 5 or 8 miles, both comparisons are false, so take the bus.

Why order matters

What if you check distance < 5 miles for bike first? At 1 mile, that check is already true. The program chooses bike and skips the walk check inside else. The walk branch can never run: every distance under 2 is also under 5.

For these less-than distance checks, put the smaller limit first.

Two separate ifs behave differently. Checking under 5 and then under 2 gives both bike and walk for 1 mile. Both conditions are true, and there is no else to skip the second check.

Give a guessing clue

Use three replies for a secret number of 7:

ask "Guess my number from 1 to 10. Type a number." and wait
if answer = 7 then
  say "You got it!"
else
  if answer < 7 then
    say "Too low!"
  else
    say "Too high!"

A guess of 7 matches the first check. A guess of 3 misses equality but is less than 7. A guess of 9 misses both and reaches the last else.

Plan tests for all the paths

In a flowchart, the first diamond's no arrow leads to the second diamond. Each yes arrow leads to its own action. For the travel rule, try 1, 2, 4, 5, and 8 miles. Those tests reach every branch and include both limits.

Key Takeaways

  • Place another choice inside else to add a third branch.
  • A chain runs the first matching branch and skips the rest.
  • The order of checks can change the answer.
  • Put the smaller limit first in the less-than distance chain.
  • Test every branch and each limit.
4

Build quizzes and games that make choices

Put your blocks to work in something another person can play. You will plan a quiz with readable feedback, then build a game with controls and rules. Building one small piece at a time lets you try each choice before adding the next. You also decide how play starts, restarts, and ends.

4.1 Make a quiz players can follow

Choose a topic and think about who will play. Plan the questions and feedback before building. A table or storyboard, a row of pictures with notes, helps keep your ideas in order.

Plan the questions

Each question needs a right answer and two replies. Here is a three-question plan:

QuestionRight answerHelpful wrong-answer reply
"What is 7 × 8? Type a number."56"Not quite. 7 × 8 = 56."
"How many legs does a spider have? Type a number."8"Not quite. Spiders have 8 legs."
"Is a whale a fish? Type yes or no.""no""Not quite. A whale is a mammal."

Plan "Correct!" for the right replies. You can add a cheer sound too. Decide these outputs before you start choosing blocks.

Build the first question

Make the host's start script:

when start button clicked
  say "Welcome to my quiz!" for 2 seconds
  ask "What is 7 × 8? Type a number." and wait
  if answer = 56 then
    say "Correct!" for 2 seconds
    play cheer sound
  else
    say "Not quite. 7 × 8 = 56." for 2 seconds

Run this question before adding the others. Try 56, then restart and try 54. Check that each reply appears in the correct branch.

Give players time to read

An instant say block may be replaced by the next question too quickly. A timed reply holds the words on screen before the script moves on. Use a time that lets your players read comfortably.

Then add question 2 after the whole choice. It needs its own ask block and comparison with 8. Question 3 follows with a comparison with "no". Each question follows ask, compare, reply.

Keep different outputs inside their matching branches. A cheer belongs with the right reply. A gentle wrong-answer sound belongs with the helpful reply. A costume change can show feedback too.

Plan how to play again

You can start the questions by clicking the host instead of the start button. A separate "Play again" button can broadcast a message to begin from question 1. Give the quiz host the matching receive script. Try the restart after finishing, and check that the first question appears again.

Key Takeaways

  • Plan questions, answers, and both replies before building.
  • Build and test one question before adding the next.
  • Keep each question in ask, compare, reply order.
  • Leave enough time to read each reply.
  • Put sounds and costume changes in their matching branches.
  • A restart message can begin the quiz from question 1.

4.2 Turn game rules into blocks

Write what the player can do and what makes them win. Then write rules as if-then sentences: “If the player touches lava, go back to the start.” Each rule tells you a condition and an action.

Separate controls and rules

Key events can move a character. A start event sets up the game. A forever loop keeps checking the rules while the player moves.

For a maze, place if touching wall? then go to starting spot inside that loop. The wall is a static object: it does not move, but touching it changes what happens to the player.

Checking only once under the start event misses later touches. The player usually starts away from the wall. By the time they reach it, that check has finished.

Build a catching game

In "Catch the apple," a basket moves left and right. Put these scripts on the basket:

when right arrow key pressed
  change x by 10

when left arrow key pressed
  change x by -10

Put the falling rules on the apple:

when start button clicked
  go to top of screen
  forever
    change y by -5
    if touching basket? then
      play sound "pop"
      go to top of screen
    if touching ground? then
      say "Missed!" for 1 second
      go to top of screen

The ground is a static object along the bottom. The apple moves down, then checks for a catch and a miss. A catch makes a pop and sends the apple back up. Touching the ground gives the miss reply and sends it back up too.

Build the fall first. Then add the basket check and test a catch. Add the ground check next and let an apple miss. Building one rule at a time helps you locate a new bug.

Give the game an ending

A maze can finish at a static finish line. Plan “If touching the finish line, say ‘You win!’ and stop.” Decide whether a lose rule restarts play or ends the game.

Try the controls, the wall, the finish, and the lose rule separately. Then play a whole round. The rules should keep being checked as the game changes, and the ending should do what you planned.

Key Takeaways

  • Write game rules as if-then sentences.
  • Use events for controls and a loop for repeated rule checks.
  • Static walls, ground, and finish lines can trigger game actions.
  • Build and test one rule at a time.
  • Plan what happens when the player wins or loses.
5

Test every branch and fix bugs

Testing means choosing inputs that check your rules. You will try every path, include the exact limits, and record what happens. When a test fails, follow the script to find the cause. Then make one repair and test again. You can also improve names and shorten blocks once the rules work.

5.1 Choose tests that try every path

A program can seem finished after one good run. But a choice has several paths. Testing means choosing inputs on purpose to check that your plan works. A bug is a mistake that makes the program do something you did not plan.

Write the expected result first

Before running a test, decide what should happen. This is the expected result. Watch the run and record the actual result. Compare them to decide whether the test passed.

For the quiz question "What is 7 × 8? Type a number," plan these tests:

InputExpected resultActual resultPassed?
56"Correct!"Record after running.Compare.
54Helpful reply giving 56Record after running.Compare.
"fifty-six"Helpful reply giving 56Record after running.Compare.

The word form does not match the number in answer = 56. This test checks the typing rule as well as the false branch. If you decide what is right only after seeing the screen, it is easy to accept a bug.

Cover true, false, and the boundary

Try at least one input for every branch. A right answer alone never tests the wrong-answer reply.

For if temperature > 80, try 95 °F for true and 60 °F for false. Also try 80 °F, the boundary or exact limit. Equal is not greater, so 80 takes else. Tests near a limit help you notice a sign that puts equality in the wrong place.

Give longer chains more tests

For walking under 2 miles, biking under 5, and bus otherwise, try 1, 2, 4, 5, and 8 miles. Expect walk, bike, bike, bus, and bus. All three branches run, and both limits are tested.

Each test follows one path through that choice. Repeating 1 mile five times still leaves the other paths untouched.

Test the triggers too

Press every control key. Click every character that should react. Try each board button and message-triggered action. A script you never start has not been tested.

Ask a friend to try your program. They may choose a surprising answer or press a control you forgot. Add a useful new test to your table when their play reveals something you missed.

Key Takeaways

  • Choose tests before running the program.
  • Record input, expected result, actual result, and pass or fail.
  • Test every branch and the exact limits.
  • Test each event and ask another player to try the program.

5.2 Find the first thing that goes wrong

When a program surprises you, compare what happened with your plan. Debugging means finding and fixing bugs. Try to explain the cause before moving blocks.

Follow a small repair plan
  1. Compare the actual result with the expected result.
  2. Find the script, trigger, or branch where things first go wrong.
  3. Explain why that part behaves that way.
  4. Change one thing.
  5. Run the tests again, including ones that passed before.

Changing several blocks at once makes it harder to tell which change helped.

Nothing happens

Start with the event. Did you choose the right key? Is the script on the right character? Are the action blocks snapped to the event? If it waits for a message, find the script that sends it. A misspelled or missing message can leave a receiver waiting.

The character walks through a wall

Suppose this is the whole rule script:

when start button clicked
  if touching wall? then
    go to starting spot

The player starts away from the wall. The check is false, and the script ends. Walking into the wall later does not restart that check.

Explain it: “The wall is checked only once.” Put the if inside a forever loop. Restart, walk into the wall, and check that the player returns. Also check that ordinary movement still works away from walls.

Every answer gets praise

A quiz checks answer = 56, but "Correct!" is attached below the whole choice. That block runs after either branch. Move it inside then. Test 56 and 54. The first should receive praise; the second should get the helpful reply.

If the check comes before ask, move ask first. If a new question compares with an old right answer, change that comparison.

A reading gets no reply

Two separate weather checks use temperature > 80 and temperature < 80. Exactly 80 meets neither. Replace them with one if-then-else. Then test 95, 80, and 60 °F.

When a rule responds to the wrong readings, read its sign aloud. Check the branch actions and the limit too. After a repair, run your full test table: a change can fix one path and break another.

Key Takeaways

  • Find and explain the cause before changing blocks.
  • Change one thing at a time.
  • Check event choice, character, attachments, and sent messages.
  • Inspect comparison signs, action placement, and repeated checks.
  • Rerun all your tests after a repair.

5.3 Improve a program that already works

A running program still needs checking against your plan. To evaluate it, go through each rule and test whether the program does what you wanted. Feedback from another player can show what needs improving.

Shorter code and less work

Shorter code uses fewer blocks for the same job. Efficient code avoids unnecessary work for the computer. These are related, but they are not the same thing.

Suppose four pairs of blocks say move 10 steps, then wait 0.5 seconds. A repeat 4 loop can hold one pair. You have fewer blocks to read and change. The computer still moves four times and waits four times.

One if-then-else can save a check. To give one reply for answer = 56, put praise in then and help in else. The comparison is checked once. Two separate ifs for opposite cases check twice.

Find a branch that is never reached

Look at a distance chain that checks under 5 miles for bike before checking under 2 miles for walk. Any walking distance is caught by the first check. The walk branch cannot run.

Try 1 mile. The first condition is true, so bike runs and the rest is skipped. Move the under-2 check first. Now 1 mile reaches walk, 4 reaches bike, and 8 reaches bus. Retest the limits of 2 and 5 miles too.

Removing blocks without checking their job can change the rules. Compare the behavior before and after an improvement, using the same tests.

Make names helpful

A message called "start race" tells you why it is sent. "message1" does not. Names such as "basket" and "finish line" help you find the character that owns a rule.

Clear names save searching when you return to your program later. They also help a friend understand your scripts.

Use a player's feedback

Ask a friend to play and watch where they pause. They might need longer feedback, a clearer restart button, or harder questions. Pick changes that help your intended players.

After adding an improvement, check the original rules as well. A new "Play again" button is useful only if it starts the quiz correctly and the right- and wrong-answer replies still work.

Key Takeaways

  • Evaluate a program by checking it against the plan.
  • Shorter code uses fewer blocks; efficient code avoids unnecessary work.
  • A loop can shorten code while keeping the same repeated actions.
  • Order checks so every intended branch can be reached.
  • Use clear names and useful player feedback.

Events and Conditions in Coding examples

5 Walkthroughs

1

Make a scene react to your signals

11 steps
Build a clicking owl, add key controls, and start two characters with a message.
  1. 1
    IntroductionGive the scene a signal

    Imagine a stage that waits for you. A click can start a sound, and a key can move a character. Each of those signals is an event, the thing that starts a script. You will build those small reactions, then start two characters together with a message they both receive. Begin by deciding which signal should start each action.

  2. 2
    AnalogyTry it with a clap

    Ask a friend to clap once. Your rule is “When I clap, raise your hand.” The clap is the event. Raising your hand is the action. Until the clap happens, you wait. A program can wait for its trigger in the same way.

  3. 3
    ExampleMake an owl hoot

    Choose the owl. Attach play sound "hoot" under when this character clicked. The click is an input. The hoot is an output you hear. Click the owl to start this short script; the sound block runs after the event is noticed.

  4. 4
    ChallengeFind what starts the glow

    A board shows a star when you shake it. What is the event, and what is the visible output?

    ---reveal---

    The shake is the event. The star on the lights is the output. Showing the star follows the shake, so it is the action the event starts.

  5. 5
    ExamplePlan a right-key control

    Write “When right arrow is pressed, the owl moves right.” On the owl, choose that key event and attach change x by 8. Try one separate press. The owl moves 8 steps. Release the key before trying another press, so you can count the short script runs.

  6. 6
    ChallengeCount the short runs

    The owl moves 8 steps for each separate right-arrow press. You press and release it three times. How far does it move?

    ---reveal---

    It moves 24 steps right: 8, then 8, then 8. The event starts the script on each press. The one move block does not keep running on its own.

  7. 7
    TipCheck the attachments

    If the owl does nothing, check the chosen key and character first. Then look for a loose move block. It must snap underneath the event. Add a separate start script to send the owl to its starting spot before another run, so you can compare tests from the same place.

  8. 8
    ExplanationLet two jobs overlap

    A script with a forever walking loop cannot reach a music block after that loop. Give the music its own start-button script. One start click now begins both jobs. Each script keeps its own block order, while the walking and music happen together.

  9. 9
    ExampleSend the same starting message

    The starter broadcasts "show time" on start. The owl listens for "show time" and hoots. The moon listens for "show time" and glows. Both receive scripts begin when the message arrives. The moon can stay in one place: a static object can still react.

  10. 10
    ChallengePredict the whole scene

    Start broadcasts "show time". The owl waits 1 second, then hoots. The moon glows immediately on receiving that message. What do you notice first?

    ---reveal---

    The moon glows first. The owl hoots after its own wait. Their scripts start together; the moon does not wait for the owl script to finish.

  11. 11
    RecapChoose the trigger, then the job

    An event starts the attached actions. Keep controls on the character they belong to. Use separate scripts for jobs that happen together, and matching message names to start receivers. Before running a scene, predict what starts immediately and what waits.

2

Follow the paths through a choice

14 steps
Use conditions to skip an action, choose between replies, and keep watching during play.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionGive your program a choice
  2. 2
    ExplanationAsk something with two answers
  3. 3
    ExampleJoin two checks
  4. 4
    ChallengeCheck both parts
  5. 5
    Key InsightFlip the answer with not
  6. 6
    ExampleLeave an action outside the if
  7. 7
    ChallengeTrace the false path
  8. 8
    ExplanationDraw the choice
  9. 9
    TipCheck again during play
  10. 10
    ExampleChoose one reply
  11. 11
    ChallengePick the block you need
  12. 12
    ExampleNotice a missing equal value
  13. 13
    ChallengePlan a rule that keeps watching
  14. 14
    RecapRead one path at a time
3

Compare values without missing the limits

15 steps
Trace a sensor rule, check typed answers, and build a three-way choice.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionLet a value choose the action
  2. 2
    ExplanationRead from left to right
  3. 3
    ExampleChoose a light rule
  4. 4
    ExampleTrace below, equal, and above
  5. 5
    ChallengeInclude the limit
  6. 6
    TipWatch for a skipped exact reading
  7. 7
    ExampleAsk for a number first
  8. 8
    ChallengeCheck what is really matched
  9. 9
    Key InsightUse each answer before the next ask
  10. 10
    ExplanationMake room for a third choice
  11. 11
    ExampleTrace the first limit
  12. 12
    ExampleTrace the second limit
  13. 13
    ChallengeRepair a hidden branch
  14. 14
    ChallengeCombine input and a chain
  15. 15
    RecapGive every value a place
4

Build a tiny quiz and a maze

12 steps
Plan useful feedback, add movement controls, and build a win rule that keeps checking.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionBuild something another person can play
  2. 2
    ExplanationPlan both kinds of reply
  3. 3
    ExampleBuild one complete question
  4. 4
    ChallengeFind the missing plan
  5. 5
    TipTest before copying
  6. 6
    ExplanationWrite the maze rules
  7. 7
    ExampleAdd the wall rule
  8. 8
    ExampleAdd the finish rule
  9. 9
    ChallengeSpot the early-only check
  10. 10
    ConnectionGive play a fresh beginning
  11. 11
    ChallengePlan a full tryout
  12. 12
    RecapKeep the plan beside the blocks
5

Test a choice, repair it, and improve it

13 steps
Use expected results to find an equality bug, then check repairs and simplify a repeated sequence.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionTry to find the paths you missed
  2. 2
    ExampleWrite the expected replies
  3. 3
    ChallengeChoose the extra test
  4. 4
    ExplanationRecord what actually happened
  5. 5
    ExampleFind the gap
  6. 6
    ExampleMake one repair
  7. 7
    ChallengeExplain another bug before fixing it
  8. 8
    TipIf nothing runs, inspect the event
  9. 9
    ExampleShorten a repeated sequence
  10. 10
    ChallengeCount the computer’s work
  11. 11
    Key InsightSave a needless comparison
  12. 12
    ChallengeCheck a player’s improvement
  13. 13
    RecapUse the plan to judge the result

Events and Conditions in Coding practice questions

50 Practice Questions in 5 sets

Set 1: Meet events and choices10 Practice Questions

Question 1 of 10

A fan turns on when temperature > 74; otherwise it turns off. What happens at 74 °F?
  1. The fan changes on and off.
  2. The fan stays off.
  3. The program gives no action.
  4. The fan turns on.
Show answerHide answer
Answer: B
At 74 °F, greater than 74 is false because the values are equal. The else action turns the fan off. Equality belongs to else here, so the choice still has an action for this reading.

Question 2 of 10

You are planning a quiz question. You have written the question and its right answer. What feedback should you also plan?
  1. One reply after every question
  2. Replies for right and wrong answers
  3. A reply for right answers only
  4. A reply for wrong answers only
Show answerHide answer
Answer: B
Plan both the right-answer and wrong-answer replies. An if-then-else needs suitable feedback in each branch. Planning only the praise leaves you without a helpful response when a player makes a mistake.

Question 3 of 10

The P key should make a bell ring. The script uses when B key pressed. What is the direct repair?
  1. Make the sound longer.
  2. Move the bell character.
  3. Add another sound block.
  4. Change the event key to P.
Show answerHide answer
Answer: D
The event is listening for B, so P does not start it. Change the chosen key to P to match the planned control. A longer sound changes the action but leaves the wrong trigger in place.

Question 4 of 10

A script checks if touching red? then say "Stop" else say "Go". The character touches blue only. What does it say?
  1. "Stop"
  2. "Stop", then "Go"
  3. "Go"
  4. No message
Show answerHide answer
Answer: C
Touching red is false, so the else branch says "Go." The false result does not skip both replies: an if-then-else runs exactly one branch whenever it reaches the choice.

Question 5 of 10

“When you click the fox, it jumps.” What is the event?
  1. The fox being clicked
  2. The fox jumping
  3. The mouse moving
  4. The fox being shown
Show answerHide answer
Answer: A
Clicking the fox is the event that starts the script. Jumping is the action that follows, so it is the output of this rule, not its trigger.

Question 6 of 10

A rectangle is 6 inches long and 4 inches wide. A script says if length = width then "Square" else "Not square". What does it say?
  1. "Not square"
  2. Neither message
  3. "Square"
  4. Both messages
Show answerHide answer
Answer: A
Six and 4 are not equal, so the condition is false and else gives "Not square." A rectangle needs equal length and width to be a square; being a rectangle alone does not pass this check.

Question 7 of 10

After you fix a sign in a game, the wall test passes. What should you do before calling the repair finished?
  1. Change another rule before testing.
  2. Delete the earlier passing tests.
  3. Run all your planned tests again.
  4. Repeat only that wall test again.
Show answerHide answer
Answer: C
Run the full planned test list, including previously passing cases. A sign change may fix the wall case while changing another path or boundary. Repeating only the repaired case leaves those possible new bugs unchecked.

Question 8 of 10

A microphone notices a clap and a character turns purple. What are the input and output in that order?
  1. Microphone; character
  2. Character; microphone
  3. Clap; color change
  4. Color change; clap
Show answerHide answer
Answer: C
The clap is the input noticed by the microphone. Turning purple is the visible output. The microphone and character are things involved in the program, but naming them does not identify what goes in and what happens next.

Question 9 of 10

A quiz has a wrong-answer reply inside else, but "Great!" is attached after the entire choice. What happens after a wrong answer?
  1. Else reply, then "Great!".
  2. Neither reply appears.
  3. Only the else reply appears.
  4. Only "Great!" appears.
Show answerHide answer
Answer: A
The false condition runs the else reply, then the script continues after the choice and says "Great!" Moving that praise into then would keep it for right answers. A block below the choice is not controlled by its condition.

Question 10 of 10

A heater uses if reading > 65: "Warm" and separately if reading < 65: "Cool". The plan says 65 should be Cool. What replacement matches the plan for every reading?
  1. If reading = 65: Cool; else: Warm.
  2. If reading < 65: Cool; else: Warm.
  3. If reading > 65: Cool; else: Warm.
  4. If reading > 65: Warm; else: Cool.
Show answerHide answer
Answer: D
Greater than 65 gives Warm, while else includes 65 and lower readings as Cool. Checking less than 65 for Cool with Warm in else would put equality in the wrong branch. The replacement also closes the original gap at 65.
Set 2: Read the blocks and predict10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

A quiz checks answer = 15. The player types "fifteen". Which branch runs?
  1. Neither branch runs.
  2. The else branch runs.
  3. Both branches run.
  4. The then branch runs.
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

A board shows a smile when button C is pressed. What is the input?
  1. The smile disappearing
  2. The lights turning on
  3. The smile appearing
  4. The button being pressed
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A door opens if you have a ticket and the door is unlocked. You have a ticket, but the door is locked. What does this rule do?
  1. Opens with one part true
  2. Opens after a lock check
  3. Opens for your ticket
  4. Keeps the door closed
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A script says if touching star? then play chime, followed by say "Keep moving!" outside the if. You are not touching the star. What happens?
  1. Only the chime plays.
  2. The chime and message happen.
  3. Only "Keep moving!" appears.
  4. Neither chime nor message happens.
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

Two scripts start on the same click. A turtle waits 3 seconds, then moves. A bird plays a 5-second sound immediately. When does the turtle begin moving?
  1. After 8 seconds
  2. After 2 seconds
  3. After 3 seconds
  4. After 5 seconds
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

A robot moves through a maze. Walls stay still. The rule sends the robot home when it touches a wall. Where does this rule belong so it keeps working during play?
  1. After the forever loop
  2. Before the start event
  3. Inside a click-only script
  4. Inside the forever loop
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A sensor is read as 63, then 57, then 53. The alarm must sound whenever a reading is below 60. What condition will catch both readings that need the alarm?
  1. Reading = 57
  2. Reading < 60
  3. Reading = 60
  4. Reading > 60
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

Four copied move-and-wait pairs become one pair inside repeat 4. What has changed?
  1. Fewer actions, same block count
  2. Same actions, fewer blocks
  3. Fewer actions and fewer blocks
  4. Same actions, more blocks
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A game should walk for distances below 3 miles, bike below 8 after that, and take the bus otherwise. A working chain uses that order. A friend moves the below-8 check first to “tidy” it. What test would show the changed behavior?
  1. 2 miles now gives bike.
  2. 8 miles now gives walk.
  3. 9 miles now gives bike.
  4. 4 miles now gives walk.
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

A two-question quiz uses number answers 16 and 9. After the first reply, it asks question 2 and still checks answer = 16. A player answers both questions correctly. What should you change?
  1. Compare question 2 with 9.
  2. Put replies after the check.
  3. Make players type "nine".
  4. Check before question 2.
Show answerHide answer

Save this lesson to see this answer.

Set 3: Connect rules, inputs, and replies10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

A game moves a boat if it is not touching land. The boat is touching land. Is the move condition true or false?
  1. True, because land is touched.
  2. False, because land is touched.
  3. False, because no key is pressed.
  4. True, because movement is allowed.
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

A quiz gives a reply, but the next question replaces it before players can read it. What change directly helps?
  1. Show the reply for 3 seconds.
  2. Remove the wrong-answer reply.
  3. Repeat the next question twice.
  4. Put feedback before the ask.
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A maze wall stays in one place but sends the player home when touched. What kind of object is the wall?
  1. A typing object
  2. A message object
  3. A static object
  4. A moving object
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A character already touches the edge. It reaches repeat until touching edge?: move 4 steps, followed by say "There!". What happens?
  1. Neither moves nor speaks.
  2. Moves once, then says "There!".
  3. Says "There!" without moving.
  4. Keeps moving and never speaks.
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

A night light should be on for readings below 40 and off for all other readings. What choice matches that rule?
  1. If reading > 40: on; else: off.
  2. If reading < 40: off; else: on.
  3. If reading = 40: on; else: off.
  4. If reading < 40: on; else: off.
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

A quiz must give one of two replies after checking an answer. What replacement avoids checking the same answer twice?
  1. One if-then-else
  2. Two if-then blocks
  3. Two event blocks
  4. One repeat-until
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A delivery rule is if distance < 3 miles then walk, else if distance < 7 miles then bike, else van. What is chosen for exactly 3 miles?
  1. Walk and bike
  2. Bike
  3. Van
  4. Walk
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

A maze program checks its rules inside forever. Touching a wall sends the player to a starting spot away from the finish. The next if checks the finish and stops on a win. The player touches only a wall. What happens in this loop visit?
  1. It goes home and shows a win.
  2. It stays at the wall and waits.
  3. It stays at the wall and wins.
  4. It goes home and keeps playing.
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

Two separate ifs say if number < 10: "Blue" and then if number < 4: "Green". What happens for 2, and what change gives only Green for numbers below 4?
  1. Both; check below 4 first in a chain.
  2. Only Green; keep the checks separate.
  3. Only Blue; add else after the second if.
  4. Both; check below 10 first in a chain.
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

A light turns on if a box is open and not empty. The box stays open. It starts with a toy inside, then the toy is removed. What does the light condition do on those two checks?
  1. False, then true
  2. True, then true
  3. True, then false
  4. False, then false
Show answerHide answer

Save this lesson to see this answer.

Set 4: Trace bugs and test the limits10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

A character has when right arrow key pressed: change x by 6. You press and release right four times. How far right does it move?
  1. 10 steps
  2. 24 steps
  3. 6 steps
  4. 18 steps
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

The rabbit should hop when clicked. Its when this character clicked script is on the bear. Which change makes the rabbit click start the hop?
  1. Change the hop distance.
  2. Click start before the rabbit.
  3. Move the script to the rabbit.
  4. Add a wait before the hop.
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A choice checks answer = 22. Then says "Well done!" and else says "Try once more." The player types 24. What reply runs?
  1. Neither reply runs
  2. "Well done!" only
  3. Both replies in order
  4. "Try once more." only
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A choice says if timer > 20 then show "Done" else show "Wait". You tested 25 and 12. What extra timer value checks the exact limit?
  1. 0
  2. 19
  3. 21
  4. 20
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

A working quiz has clear replies, but a younger player says the replies vanish too fast. You lengthen them. How should you evaluate the change?
  1. Test the right answers only.
  2. Try both replies with that player.
  3. Count blocks without running it.
  4. Ask the player to read faster.
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

A badge appears if you finish a puzzle or help a friend. You do both. What happens, and why?
  1. A badge; at least one part is true.
  2. No badge; only one task may count.
  3. Two badges; each true part adds one.
  4. No badge; both parts cancel out.
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A size chain gives Small below 6, Medium below 12 after that, and Large otherwise. Which test list tries all three branches and both exact limits?
  1. 5, 6, 11, 12, 14
  2. 6, 7, 8, 12, 14
  3. 4, 5, 7, 10, 11
  4. 5, 7, 9, 13, 14
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

A falling pear checks for the tray and then the floor inside forever. Touching the tray plays a sound and sends the pear to the top. The top touches neither object. What happens next in this loop visit?
  1. It runs the tray sound again.
  2. It gives the floor-miss reply.
  3. It checks the floor at the top.
  4. It checks the floor at the tray.
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A quiz asks for a number answer of 17. The player types "seventeen". The quiz gives the wrong-answer reply and immediately asks another question. What two changes make the typing rule clearer and the reply readable?
  1. Ask for words; keep the check.
  2. Ask for digits; time the reply.
  3. Check first; then time the ask.
  4. Time the ask; skip the reply.
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

A start script returns a runner to its starting spot. Right arrow moves it 9 steps right, and left arrow moves it 9 steps left. You press right three times, left once, then start. Where does the runner end?
  1. 27 steps to the right
  2. 18 steps to the right
  3. 9 steps to the right
  4. At its starting spot
Show answerHide answer

Save this lesson to see this answer.

Set 5: Solve programming puzzles10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

When should you write the expected result in a test table?
  1. After changing the code
  2. After watching the result
  3. After all tests have passed
  4. Before running the test
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

On start, a game checks if touching gem? then play chime once and ends that script. You start away from the gem, then walk onto it. How should you change the script to notice later touches?
  1. Move the chime after the if.
  2. Put the if inside forever.
  3. Put a wait after the if.
  4. Put the if before start.
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

After a quiz finishes, a “Try again” button broadcasts "new quiz". The host listens for "begin quiz". Clicking the button does nothing. What change makes that button restart the host?
  1. Give the button a longer wait.
  2. Move replies outside the choices.
  3. Match the host to "new quiz".
  4. Change the quiz answer checks.
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A secret number is 11. The chain says if answer = 11: "Yes!"; else if answer < 11: "Too low!"; else: "Too high!". What happens for a guess of 13?
  1. "Too high!"
  2. "Too low!"
  3. "Too low!", then "Too high!"
  4. "Yes!"
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

A quiz asks "What is 3 × 4?", then asks "What is 2 × 9?" before checking answer = 12. The player types 12, then 18. What value does that check use?
  1. 9
  2. 12
  3. 18
  4. 30
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

On start, the program broadcasts "fly", waits 1 second, then broadcasts "float". The kite receives "fly", waits 2 seconds, then moves. The cloud receives "float" and moves immediately. Which character moves first, and when?
  1. Cloud after 1 second
  2. Kite after 2 seconds
  3. Kite after 1 second
  4. Cloud after 2 seconds
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A size program should choose Small below 5, Medium below 11 after that, and Large otherwise. Tests give Small for 4, Medium for 5, and Medium for 11. What mistaken check would produce all three results?
  1. The first check uses value < 6.
  2. The second check uses value < 12.
  3. The second check uses value < 10.
  4. The first check uses value < 4.
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

A robot checks if touching sand? then move 2 steps else move 7 steps, then moves 3 more steps outside the choice. It starts off the sand. How far does this visit to the script move it?
  1. 7 steps
  2. 5 steps
  3. 10 steps
  4. 12 steps
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A quiz asks "What is 4 + 3?", checks answer = 7, then asks "What is 5 + 8?" but still checks answer = 7. A player types both right numbers. What feedback follows?
  1. Right, then wrong
  2. Wrong, then wrong
  3. Wrong, then right
  4. Right, then right
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

A program should give "Small" below 4, "Medium" from 4 up to but not including 9, and "Large" from 9 upward. Its chain checks value < 9 for Medium first, then value < 4 for Small. What repair works?
  1. Keep the order; swap both labels.
  2. Remove else between the checks.
  3. Change the final else to Small.
  4. Check below 4 for Small first.
Show answerHide answer

Save this lesson to see this answer.

Stuck on your own question? Homework Help

Key Terms

57 Key Terms, each with its definition

A

Action
An action is something a program does when it runs an instruction.
After the click, playing a meow sound is the cat script's action.
Actual result
An actual result is what really happens when you run a test.
Record "no sound" as the actual result when the bell script fails.
Algorithm
An algorithm is a set of steps planned to solve a problem.
Write an algorithm for what the bird does when each key is pressed.
And
And joins conditions so the result is true only when both parts are true.
"Saturday and sunny" is false on a rainy Saturday.
Answer block
The answer block holds the latest reply that the player submitted to an ask block.
Check the answer block before asking the next quiz question.
Ask block
An ask block shows a question and waits for the player to type a reply and press Enter.
The ask block collects the guess before the program checks it.

B

Boundary
A boundary is the exact limit used in a comparison or choice.
Test 80 as the boundary in temperature > 80.
Branch
A branch is a path through a choice, such as running an action or skipping it.
Test each branch by trying a right answer and a wrong answer.
Broadcast
A broadcast sends a named message inside a program to start matching receive scripts.
The starter broadcasts "race" so both runners can begin together.
Bug
A bug is a mistake that makes a program do something different from what was planned.
Praise placed after the whole quiz choice is a bug if wrong answers get it.

C

Comparison
A comparison checks two values and gives a true-or-false result.
Use a comparison to check whether a timer has passed 30 seconds.
Condition
A condition is a question or statement with a true-or-false answer when checked.
The condition asks whether the player is touching the door.
Controls
Controls are the inputs a player uses to make things happen in a game.
The left and right arrow keys are controls for the basket.

D

Debugging
Debugging means finding the cause of a bug, fixing it, and checking the repair.
Debugging a buggy maze game reveals that its wall condition was checked only once.

E

Efficient code
Efficient code avoids work the computer does not need to do.
One if-then-else gives two replies while checking the answer only once.
Else branch
The else branch holds the actions for a false if condition.
Put the helpful wrong-answer reply in the else branch.
Else-if chain
An else-if chain checks further choices inside else and runs the first matching branch.
A guessing chain can choose correct, too low, or too high.
Equal to
Equal to checks whether two values match, using the sign = in these blocks.
Use answer = 8 to check a number answer of 8.
Evaluate
To evaluate a program is to judge how well it meets its plan and helps its players.
Evaluate the restart by checking that the first question appears again.
Event
An event is something that happens that a program can notice, such as a key being pressed.
Clicking the rabbit is the event that starts its hop script.
Event block
An event block starts the attached script when its matching event happens.
Put a sound block under the event block for a character click.
Expected result
An expected result is what you predict should happen before you run a test.
If trips of 5 miles or more go by bus, write "bus" as the expected result for exactly 5 miles.

F

False
False means that a checked condition does not hold at that moment, like a no answer.
"Is it raining?" is false when there is no rain.
Feedback
Feedback is a response that helps a player see how their answer or action worked.
"Not quite. Spiders have 8 legs" gives useful feedback after a miss.
Final else
The final else gives the action for values that failed all earlier checks in a chain.
In a chain that picks how to travel, the final else sends the longest trips to the bus.
Flowchart
A flowchart is a picture of steps and choices, with arrows showing the paths.
Draw a diamond for the condition and label its arrows yes and no.

G

Game rule
A game rule links a situation in the game to what should happen next.
The rule sends the player home if the character touches lava.
Greater than
Greater than checks whether the value on the left is bigger than the value on the right.
The condition reading > 80 is false when the reading is exactly 80.

I

If-then
An if-then runs its inside blocks when its condition is true and skips them when it is false.
Use if-then to play a ding when the player touches a star.
If-then-else
An if-then-else runs one branch for a true condition and the other for false.
The quiz uses if-then-else to choose praise or a helpful hint.
Input
An input is something going into a computer, such as a click or a button press.
Pressing button A gives the board an input to react to.

L

Less than
Less than checks whether the value on the left is smaller than the value on the right.
The condition distance < 2 is true for a distance of 1 mile.

N

Nested choice
A nested choice is a choice placed inside a branch of another choice.
A biking check placed inside the else branch of an earlier check is a nested choice.
Not
Not flips a condition, changing true to false and false to true.
If touching lava is false, not touching lava is true.

O

Object
An object is a character or other thing in a block program that can have its own scripts.
The crab object has controls separate from the swimming fish.
Or
Or joins conditions so the result is true when one part or both parts are true.
"Birthday or chores finished" works even when both happen.
Output
An output is something a computer does that you can see or hear.
A heart shown on the board when a button is pressed is an output of the button script.

P

Parallel scripts
Parallel scripts are scripts that run at the same time, each following its own blocks.
Parallel scripts let the music play while the fish swims.

R

Repeat-until loop
A repeat-until loop checks before each repeat and stops when its condition is true.
Repeat moving until the character touches the edge.
Restart
A restart begins play again from the planned beginning.
A "Play again" button can send the message that restarts the quiz.

S

Script
A script is a connected set of blocks that run in order in a program.
The arrow-key script moves the basket when you press right.
Selection
Selection chooses which blocks run by checking a condition.
Selection makes the character chime only when it touches a coin.
Sensor
A sensor notices something around a device, such as light, and provides a reading.
A light sensor supplies the number for the night-light condition.
Setup
Setup prepares a program for a fresh run, such as putting characters at their starting spots.
The setup shows the hidden character before the game begins.
Shorter code
Shorter code does the same planned job with fewer blocks to read and change.
A repeat loop makes four copied pairs of actions into shorter code.
Sprite
A sprite is another name used for a character or object in some block languages.
The bird sprite changes costumes while its animation script runs.
Static object
A static object stays in one place while the program runs.
The finish line is a static object that the racer can reach.
Storyboard
A storyboard is a row of pictures with notes showing how a quiz or scene will unfold.
Sketch the welcome, questions, and ending in your storyboard.

T

Test table
A test table records inputs, expected results, actual results, and pass or fail.
Add a row to the test table for a reading exactly at the limit.
Testing
Testing means running a program with chosen inputs to check whether it follows the plan.
Testing a wrong answer checks a different branch from testing a right one.
Then branch
The then branch holds the actions for a true if condition.
Put "Correct!" in the then branch of a right-answer check.
Timed reply
A timed reply stays visible for a set time before the script continues.
A 2-second timed reply lets the player read "Correct!" before moving on.
Trigger
A trigger is the event that makes a script begin its actions.
The space key is the trigger for the bird to fly upward.
True
True means that a checked condition holds at that moment, like a yes answer.
"Touching the wall?" is true while the character touches it.

U

Unreachable branch
An unreachable branch is a path that cannot run because of how the checks are arranged.
Checking under 5 first makes the later under-2 branch unreachable.

W

Win condition
A win condition states what must be true for a player to win the game.
Touching the finish line meets the maze game's win condition.

X

x position
The x position tells where a character is from left to right on the screen.
Changing x by 10 moves the character 10 steps to the right.

About this lesson

By StudeliReport a mistake

Make your own Study Materials

Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.

Get Started