1. Build this in Design Mode first
STEP 1Create these elements on screen1 with these exact IDs and starting text.
| Type | ID | Text |
|---|---|---|
| Label | targetLabel | Target: -- |
| Button | circleBtn | Circle |
| Button | squareBtn | Square |
| Button | triangleBtn | Triangle |
| Label | feedbackLabel | Feedback: -- |
| Button | newRoundBtn | New Round |
2. Switch to Code Mode
STEP 2Copy this starter code into Code Mode and fill in the marked STEPs. Same pattern as tonight's demo — keep setup separate from click evaluation.
// SETUP — already works — do not edit
var shapes = ["Circle", "Square", "Triangle"];
var targetShape = "";
function startNewRound() {
targetShape = shapes[randomNumber(0, 2)];
setText("targetLabel", "Target: " + targetShape);
setText("feedbackLabel", "Feedback: --");
}
// STEP 1: write checkGuess(guess), comparing guess to targetShape with
// ===, same pattern as tonight's demo.
// STEP 2: wire circleBtn, squareBtn, and triangleBtn to call checkGuess
// with their own shape name.
// STEP 3: wire newRoundBtn to call startNewRound(), and call
// startNewRound() once more outside any handler so the first round is
// ready immediately.
3. Check yourself
STEP 3- Click
newRoundBtnseveral times and confirm the target changes. - Guess correctly and incorrectly and confirm the feedback matches.
- Confirm a new round clears the old feedback.
Try it for real before checking the answer key.
Answer key
var shapes = ["Circle", "Square", "Triangle"];
var targetShape = "";
function startNewRound() {
targetShape = shapes[randomNumber(0, 2)];
setText("targetLabel", "Target: " + targetShape);
setText("feedbackLabel", "Feedback: --");
}
// STEP 1
function checkGuess(guess) {
if (guess === targetShape) {
setText("feedbackLabel", "Feedback: Correct!");
} else {
setText("feedbackLabel", "Feedback: Try again!");
}
}
// STEP 2
onEvent("circleBtn", "click", function() {
checkGuess("Circle");
});
onEvent("squareBtn", "click", function() {
checkGuess("Square");
});
onEvent("triangleBtn", "click", function() {
checkGuess("Triangle");
});
// STEP 3
onEvent("newRoundBtn", "click", function() {
startNewRound();
});
startNewRound();