Using if and else inside a function
A function can use if and else to make a decision, then return a different value from each branch. A default return at the end covers every other case.
Understanding Using if and else inside a function in ACARA Digital Technologies Years 7–8
What it does: Each branch has its own return, so the result depends on whether the condition is true or false. The final return runs only when both conditions are false, so the function never returns undefined. 60 is not at least 80, so the if branch is skipped. The default return at the end gives "B". return ends the function immediately. Any code after it in that call is skipped. 72 fails the first test but passes score >= 70, so the else if branch returns "B". The default "C" is never reached. Use return "A"; so the caller receives the grade as a value it can store or use.
Common mistakes: The closing bracket after the condition is missing. It should be if (score >= 80) {. JavaScript declares a function with the keyword function, not func. It should be function gradeFor(score) {.
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.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
if (score >= 80) { return "A"; }Fill in the Blanks
Spot the Error
Student with a class code? Join your class →