← ACARA Digital Technologies Years 7–8

Functions that return true or false

Uses a function that returns true or false directly as the if condition, so the code inside runs only when the call isAdult(age) gives back true.

Understanding Functions that return true or false in ACARA Digital Technologies Years 7–8

What it does: The comparison age >= 18 produces a boolean, and returning it means the function answers true or false. isEven(n) returns true or false, so it works as the if condition by itself. The call isAdult(age) already gives back true or false, so it can go straight inside the brackets. The second option is also missing a closing bracket. Boolean functions are often named like a yes/no question, such as isAdult, isEven or hasPassed. This makes if (isAdult(age)) easy to read. Without return, the boolean is never sent back, so an if using isAdult(age) would never run.

Common mistakes: A single = assigns instead of comparing, so the function returns 0 and never true or false. A comparison needs ===: return r === 0;. => is not a comparison operator, so this line is a syntax error. The 'greater than or equal to' operator is >=, so it should be return age >= 18;.

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 611–623) and word search (Modules 611–634).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which function returns a boolean?
function isEven(n) { return n % 2; }function isEven(n) { return n % 2 === 0; }
Matches
function isAdult(age) { age >= 18; }
↓
The function never uses return, so the comparison result is lost and the call gives back undefined instead of true or false. Fix: return age >= 18;
Applying
Meanings
Term
if (isAdult(age))
Meaning
Uses a function that returns true or false directly as the if condition, so the code inside runs only when the call isAdult(age) gives back true.
Practice
function isAdult(age) {
Testing
Gaps
return n % 2 0;
Check Answer
Spots
2 let r = n % 2;
3 return r = 0;

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

The 'Octopus' badge — Multi-Tasker, 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 function returns a boolean?
A. function isEven(n) { return n % 2; }
B. function isEven(n) { return n % 2 === 0; } ✓
n % 2 === 0 is a comparison, so it gives back true or false. n % 2 gives back a number (0 or 1), not a boolean.
2. Which if statement uses a boolean function correctly as its condition?
A. if (isAdult(age)) { ✓
B. if (isAdult(age) === true {
The call isAdult(age) already gives back true or false, so it can go straight inside the brackets. The second option is also missing a closing bracket.
3. What does isAdult(20) return if the function is: function isAdult(age) { return age >= 18; }
A. true ✓
B. 20
The function returns the result of the comparison 20 >= 18, which is true. It does not return the number that was passed in.
4. Which function returns a comparison result directly?
A. function isPassing(mark) { return mark >= 50; } ✓
B. function isPassing(mark) { mark >= 50; }
Without the return keyword, the comparison is worked out and then thrown away. The call gives back undefined, so an if would never run.
5. Which is the better way to write this function?
A. if (age >= 18) { return true; } else { return false; }
B. return age >= 18; ✓
Both work, but a comparison already gives true or false, so returning it directly is shorter and clearer.

Match the Pairs

function isEven(n) { return n % 2 === 0; } → A function that returns true if n is even and false if it is odd
if (isAdult(age)) { console.log("Welcome"); } → Runs the code inside only when isAdult(age) gives back true
A function can return a comparison directly, because the comparison already gives true or false → function isAdult(age) { return age >= 18; }
The call to a boolean function can be used on its own as the condition of an if → if (isEven(n)) { console.log("Even"); }
function isAdult(age) { age >= 18; } → The function never uses return, so the comparison result is lost and the call gives back undefined instead of true or false. Fix: return age >= 18;
if (isEven) { console.log("Even"); } → The function is not called because the brackets and argument are missing. isEven alone is the function itself, not true or false. Fix: if (isEven(n))

Key Term

if (isAdult(age))
Uses a function that returns true or false directly as the if condition, so the code inside runs only when the call isAdult(age) gives back true.

Fill in the Blanks

1. function isEven(n) { return n % 2 === 0; }
Hint: Type the operator that checks whether the remainder is exactly equal to zero.
2. function isAdult(age) { return age >= 18; }
Hint: Type the comparison operator for 'greater than or equal to'.
3. if (isAdult(age)) { console.log("You can vote!"); }
Hint: Type the name of the function that checks the age and gives back true or false.
4. function isEven(n) { return n % 2 === 0; }
Hint: Type the keyword that sends the true or false result back to the caller.
5. if (!isEven(n)) { console.log("Odd number"); }
Hint: Type the logical operator that flips true to false, so the code runs when the number is not even.

Spot the Error

Question 1
A function isEven(n) {
B let r = n % 2;
C return r = 0;
D }
Line C — A single = assigns instead of comparing, so the function returns 0 and never true or false. A comparison needs ===: return r === 0;
Question 2
A function isAdult(age) {
B return age => 18;
C }
D if (isAdult(20)) {
E console.log('Adult');
F }
Line B — => is not a comparison operator, so this line is a syntax error. The 'greater than or equal to' operator is >=, so it should be return age >= 18;
Question 3
A function isAdult(age) {
B return age >= 18;
C }
D if (isAdult) {
E console.log('Adult');
F }
Line D — Without the brackets and argument, isAdult is just the function itself, not a call, so the condition is always truthy. It should call the function: if (isAdult(20)) {
Question 4
A function isEven(n {
B return n % 2 === 0;
C }
D if (isEven(7)) {
E console.log('Even');
F }
Line A — The closing bracket after the parameter list is missing. It should be function isEven(n) {
Question 5
A function isAdult(age) {
B if (age >= 18) {
C return True;
D }
E return false;
F }
Line C — JavaScript booleans are lowercase. True is not defined and causes a ReferenceError. It should be return true;

Student with a class code? Join your class →