? Week 5 Day 1 Challenge — School Zone Speed Checker
CodeX Academy · Level 1 — App Lab · Lesson 6

School Zone Speed Checker

Optional extra practice for Lesson 6's if-statements. Same skill as tonight's demo — one condition, two outcomes, no arrays or input yet — a different scenario, on your own.

1. Build this in Design Mode first

STEP 1

Create these elements on screen1 with these exact IDs and starting text.

TypeIDText
LabelspeedLabelSpeed: --
LabelstatusLabelStatus: --
Buttonbtn10Speed: 10
Buttonbtn25Speed: 25
Buttonbtn26Speed: 26
Buttonbtn40Speed: 40

2. Switch to Code Mode

STEP 2

Copy this starter code into Code Mode. Three of the four button handlers already echo their speed into speedLabel — your job is the one if-statement, built once inside btn25's handler, then copied into the other three.

Before you type anything, say the rule out loud: 25 mph or under is OK; anything over that is Over the limit.

// SETUP (already works — do not edit)
onEvent("btn10", "click", function() {
  var speed = 10;
  setText("speedLabel", "Speed: " + speed);
  // (fill in after btn25 works)
});

onEvent("btn26", "click", function() {
  var speed = 26;
  setText("speedLabel", "Speed: " + speed);
  // (fill in after btn25 works)
});

onEvent("btn40", "click", function() {
  var speed = 40;
  setText("speedLabel", "Speed: " + speed);
  // (fill in after btn25 works)
});

// STEP 1: Build this one first. Write ONE if-statement that sets
// statusLabel:
//   speed <= 25   -> "Status: OK"
//   otherwise     -> "Status: Over the limit"
// A single condition with two outcomes — not a chain.
onEvent("btn25", "click", function() {
  var speed = 25;
  setText("speedLabel", "Speed: " + speed);


});

3. Copy the pattern into the other three buttons

STEP 3

Once btn25 works, copy the exact same if-statement into btn10, btn26, and btn40's handlers. Same repetition idea as the demo — you'll avoid this retyping later once you learn functions.

4. Check yourself — this is the actual lesson

STEP 4

Click each button and predict the status before you click. The four speeds are chosen on purpose to sit right on the one boundary:

ButtonWhat it should test
10clearly OK
25exactly the cutoff — does your <= actually include it?
26one over the cutoff
40clearly over the limit

If 25 and 26 give the same status, that's a boundary bug — re-read your comparison operator (<, <=, >=, >) before assuming the condition is wrong.

Try it for real before checking the answer key.

Answer key
onEvent("btn10", "click", function() {
  var speed = 10;
  setText("speedLabel", "Speed: " + speed);
  if (speed <= 25) {
    setText("statusLabel", "Status: OK");
  } else {
    setText("statusLabel", "Status: Over the limit");
  }
});

onEvent("btn25", "click", function() {
  var speed = 25;
  setText("speedLabel", "Speed: " + speed);
  if (speed <= 25) {
    setText("statusLabel", "Status: OK");
  } else {
    setText("statusLabel", "Status: Over the limit");
  }
});

onEvent("btn26", "click", function() {
  var speed = 26;
  setText("speedLabel", "Speed: " + speed);
  if (speed <= 25) {
    setText("statusLabel", "Status: OK");
  } else {
    setText("statusLabel", "Status: Over the limit");
  }
});

onEvent("btn40", "click", function() {
  var speed = 40;
  setText("speedLabel", "Speed: " + speed);
  if (speed <= 25) {
    setText("statusLabel", "Status: OK");
  } else {
    setText("statusLabel", "Status: Over the limit");
  }
});