← ACARA Digital Technologies Years 7–8

Compound conditions inside an if

A compound condition joins several tests in one if using && (and), the or operator and ! (not). Brackets set the order. Use it for range checks, like age between 10 and 15.

Understanding Compound conditions inside an if in ACARA Digital Technologies Years 7–8

What it does: The brackets make JavaScript work out the || part first. Without them && is checked before ||, which can change the answer. ! flips a boolean from true to false or false to true. Here the block runs when the score is 50 or more and isAbsent is false. && needs BOTH tests to be true. With ||, every number passes, because any number is either 10 or more, or 15 or less. x > 3 is true, but x < 4 is false. With && one false test makes the whole condition false. || means OR, so only one of the two tests has to be true. It is a good way to catch values outside a range.

Common mistakes: A range check needs both tests to be true, so it must use &&. With ||, every number passes, because every number is at least 10 or at most 15. It should be: if (age >= 10 && age <= 15) {. To test for outside a range, use ||. No temperature can be below 5 and above 35 at the same time, so && is never true. It should be: if (temp < 5 || temp > 35) {.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 583–598) and word search (Modules 583–613).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which if checks that age is between 10 and 15 (including both)?
if (age >= 10 && age <= 15)if (age >= 10 || age <= 15)
Matches
if (age >= 10 && <= 15)
↓
The second test is missing the variable name. Each side of && must be a full condition, so it should be age <= 15.
Applying
Meanings
Term
if (age >= 10 && age <= 15)
Meaning
A compound condition joins several tests in one if using && (and), the or operator and ! (not). Brackets set the order. Use it for range checks, like age between 10 and 15.
Practice
let age = 12;
Testing
Gaps
if (age >= 10 age <= 15) {
Check Answer
Spots
2// Is age from 10 to 15?
3if (age >= 10 || age <= 15) {

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Warthog' badge — Definition Digger, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which if checks that age is between 10 and 15 (including both)?
A. if (age >= 10 || age <= 15)
B. if (age >= 10 && age <= 15) ✓
&& needs BOTH tests to be true. With ||, every number passes, because any number is either 10 or more, or 15 or less.
2. Which if is true when score is OUTSIDE the range 40 to 90?
A. if (score < 40 && score > 90)
B. if (score < 40 || score > 90) ✓
No number is below 40 and above 90 at the same time, so && is never true. Use || so that either test can pass.
3. What does this condition do? if (temp > 20 && temp < 30)
A. It is true only when temp is between 20 and 30 ✓
B. It is true for any temp value at all
&& joins two tests and both must be true, so temp must be above 20 and below 30.
4. x is 5. What is the result of (x > 3 && x < 4)?
A. false ✓
B. true
x > 3 is true, but x < 4 is false. With && one false test makes the whole condition false.
5. x is 5. What is the result of (x < 3 || x > 4)?
A. true ✓
B. false
x < 3 is false, but x > 4 is true. With || one true test is enough to make the whole condition true.

Match the Pairs

if (age >= 10 && age <= 15) → Runs only when age is between 10 and 15 inclusive, because both tests must be true
if (score < 0 || score > 100) → Runs when score is outside the range 0 to 100, because either test being true is enough
Use brackets so the OR is checked first, then the result is combined with AND → if (age >= 10 && (house === "Red" || house === "Blue"))
Use ! to check that something is NOT true, together with another test → if (score >= 50 && !isAbsent)
if (age >= 10 && <= 15) → The second test is missing the variable name. Each side of && must be a full condition, so it should be age <= 15.
if (temp < 0 && temp > 40) → && is the wrong operator for outside a range. No number is below 0 and above 40 at the same time, so it should be ||.

Key Term

if (age >= 10 && age <= 15)
A compound condition joins several tests in one if using && (and), the or operator and ! (not). Brackets set the order. Use it for range checks, like age between 10 and 15.

Fill in the Blanks

1. let age = 12; if (age >= 10 && age <= 15) { console.log("In range");
Hint: Type the operator that needs BOTH tests to be true.
2. let age = 18; if (age < 10 || age > 15) { console.log("Outside");
Hint: Type the operator that is true when EITHER test is true.
3. let done = false; if (!done && score >= 50) { console.log("Keep going");
Hint: Type the operator that flips a boolean to its opposite.
4. if (isMember && (age < 10 || age > 15)) { console.log("Special price"); }
Hint: Inside the brackets, type the operator that lets either age test pass.
5. let temp = 25; if (temp >= 20 && temp <= 30) { console.log("Nice day");
Hint: Type the variable name that is being checked against the upper limit.

Spot the Error

Question 1
A let age = 12;
B // Is age from 10 to 15?
C if (age >= 10 || age <= 15) {
D console.log('Yes');
E }
Line C — A range check needs both tests to be true, so it must use &&. With ||, every number passes, because every number is at least 10 or at most 15. It should be: if (age >= 10 && age <= 15) {
Question 2
A let temp = 38;
B if (temp < 5 && temp > 35) {
C console.log('Extreme');
D }
Line B — To test for outside a range, use ||. No temperature can be below 5 and above 35 at the same time, so && is never true. It should be: if (temp < 5 || temp > 35) {
Question 3
A let hour = 14;
B let open = false;
C // Open from 9 to 17
D if (hour >= 9 && < 17) {
E open = true;
F }
Line D — Each side of && must be a full test. The second test is missing the variable hour. It should be: if (hour >= 9 && hour < 17) {
Question 4
A if (!isRaining && temp > 20 {
B console.log('Picnic!');
C }
Line A — The closing bracket of the condition is missing. The whole compound condition must sit inside matching brackets before the {. It should be: if (!isRaining && temp > 20) {
Question 5
A let pts = 85;
B if (80 <= pts <= 100) {
C console.log('A');
D }
Line B — JavaScript cannot chain comparisons like this. It works out 80 <= pts first, which gives true or false, then compares that with 100. Write two tests joined by &&: if (pts >= 80 && pts <= 100) {

Student with a class code? Join your class →