Writing a program that uses functions and control structures
Build a program from small functions that take parameters and return values, then call them from a short main section. Add a comment above each function and test each one separately.
Understanding Writing a program that uses functions and control structures in ACARA Digital Technologies Years 7–8
What it does: The main section only calls the function addUp and prints the result, while the function holds the real steps. The comment sits above the function and describes its job, which helps other people read and fix the program. Brackets with an argument are needed to call a function. Without them, double just refers to the function and does not run it. A returned value can be stored, tested in an if statement or reused. A printed message cannot be reused. Putting a loop inside a function lets you reuse it by calling it, instead of repeating the same code. Testing each function on its own with a known input shows whether that function works before it is used in the whole program.
Common mistakes: The call has a spelling mistake. The function is declared as square, so squar is not defined and causes a ReferenceError. It should be console.log(square(5));. A JavaScript function is declared with the keyword function, not func. The line should be function isEven(n) {.
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 635–666) and word search (Modules 635–695).
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
function double(n) { return n * 2; }Fill in the Blanks
Spot the Error
Student with a class code? Join your class →