1. Build this in Design Mode first
STEP 1Create these elements on screen1 with these exact IDs and starting text.
| Type | ID | Text |
|---|---|---|
| Label | countLabel | Push-ups: 0 |
| Button | addBtn | +1 |
| Button | tensBtn | +10 |
| Button | resetBtn | Reset |
2. Switch to Code Mode
STEP 2Copy 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
addBtnfive times fast. Does the count keep up exactly? - Click
tensBtnonce, thenaddBtntwice, thenresetBtn. Predict the count after each click before you look. - Click
resetBtnwhen 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();
});