? Week 5 Day 3 Challenge — Field Trip Permission Checker
CodeX Academy · Level 1 — App Lab · Lesson 8

Field Trip Permission Checker

Optional extra practice combining two conditions into one if with a boolean operator. New challenge — this night didn't have one before.

1. Build this in Design Mode first

STEP 1

Create these elements on screen1 with these exact IDs and starting text.

TypeIDText
LabelagePromptEnter your age:
TextInputageInput(leave blank)
LabelslipPromptSigned permission slip? (yes or no)
TextInputslipInput(leave blank)
ButtoncheckBtnCheck
LabelresultLabelResult: --

2. Switch to Code Mode

STEP 2

Copy 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.

AgeSlipBoth true?Predicted result
12yesyes/yesshould clear
12noyes/noshould NOT clear
8yesno/yesshould NOT clear
8nono/noshould 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.");
  }
});