? Week 4 Day 3 Challenge — Push-Up Counter
CodeX Academy · Level 1 — App Lab · Lesson 5

Push-Up Counter

Optional extra practice for Lesson 5 (clicker game). Same skill as tonight's demo (score + shared display function) — 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
LabelcountLabelPush-ups: 0
ButtonaddBtn+1
ButtontensBtn+10
ButtonresetBtnReset

2. Switch to Code Mode

STEP 2

Copy this starter code into Code Mode and fill in the numbered STEPs. Notice the code already gives you one function, updateCount(), that does nothing but refresh the label. Every STEP should change the count variable, then call that one function — not write its own setText line.

// SETUP (already works — do not edit)
var count = 0;
function updateCount() {
  setText("countLabel", "Push-ups: " + count);
}

// STEP 1: When addBtn is clicked, add 1 to count, then call updateCount().


// STEP 2: When tensBtn is clicked, add 10 to count, then call
// updateCount().


// STEP 3: When resetBtn is clicked, set count back to 0, then call
// updateCount().

3. Check yourself

STEP 3
  • Click addBtn five times fast. Does the count keep up exactly?
  • Click tensBtn once, then addBtn twice, then resetBtn. Predict the count after each click before you look.
  • Click resetBtn when the count is already 0. Nothing should break.
  • Try it for real before checking the answer key.
Answer key
var count = 0;
function updateCount() {
  setText("countLabel", "Push-ups: " + count);
}

// STEP 1
onEvent("addBtn", "click", function() {
  count = count + 1;
  updateCount();
});

// STEP 2
onEvent("tensBtn", "click", function() {
  count = count + 10;
  updateCount();
});

// STEP 3
onEvent("resetBtn", "click", function() {
  count = 0;
  updateCount();
});