? Week 5 Day 5 Challenge — Shape Sleuth
CodeX Academy · Level 1 — App Lab · Lesson 10

Shape Sleuth

Optional extra practice. Same random-target, click-evaluation, reset pattern as tonight's Color Sleuth — 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
LabeltargetLabelTarget: --
ButtoncircleBtnCircle
ButtonsquareBtnSquare
ButtontriangleBtnTriangle
LabelfeedbackLabelFeedback: --
ButtonnewRoundBtnNew Round

2. Switch to Code Mode

STEP 2

Copy 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 newRoundBtn several 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();