1. Build this in Design Mode first
STEP 1Create these elements on screen1 with these exact IDs and starting text.
| Type | ID | Text |
|---|---|---|
| Label | agePrompt | Enter your age: |
| TextInput | ageInput | (leave blank) |
| Label | slipPrompt | Signed permission slip? (yes or no) |
| TextInput | slipInput | (leave blank) |
| Button | checkBtn | Check |
| Label | resultLabel | Result: -- |
2. Switch to Code Mode
STEP 2Copy this starter code into Code Mode and fill in the marked STEP.
onEvent("checkBtn", "click", function() {
var age = getNumber("ageInput");
var slip = getText("slipInput");
// STEP: combine both conditions into one if using && (AND):
// age is 10 or older AND slip is exactly "yes"
// -> "Result: Cleared for the trip!"
// otherwise
// -> "Result: Not cleared yet."
});
3. Check yourself — predict all four combinations before you test
STEP 3&& needs BOTH sides true. Predict each row's result before clicking.
| Age | Slip | Both true? | Predicted result |
|---|---|---|---|
| 12 | yes | yes/yes | should clear |
| 12 | no | yes/no | should NOT clear |
| 8 | yes | no/yes | should NOT clear |
| 8 | no | no/no | should NOT clear |
Only the first row should clear — that's what AND means. If any other row also clears, recheck that you used && and not ||.
Try it for real before checking the answer key.
Bonus — try OR instead
Change && to || and re-test the same four rows. Now more than one row should clear. Write down, in your own words, why && and || gave different results on the exact same four test cases.
Answer key
onEvent("checkBtn", "click", function() {
var age = getNumber("ageInput");
var slip = getText("slipInput");
if (age >= 10 && slip === "yes") {
setText("resultLabel", "Result: Cleared for the trip!");
} else {
setText("resultLabel", "Result: Not cleared yet.");
}
});