Passing an array to a function
A function with a parameter that receives an array when called, e.g. total([4, 7, 9]). The function can loop over it, return a new array, or change the original array.
Understanding Passing an array to a function in ACARA Digital Technologies Years 9–10
What it does: The array in square brackets is the argument and it is received by the function's parameter. map builds a new array, and returning it gives the caller the new array while nums stays the same. scores is the parameter name. It receives the whole array. Use scores.length if you need the number of items. Inside the function, list is the array [5, 6, 7]. list[0] reads the first item, which is 5. The function receives the same array, not a copy. Mutating methods like push change the original array. The loop adds up the values correctly, but the result is lost unless the function returns sum.
Common mistakes: The variable is called sum, not sums, so this causes a ReferenceError. The function should return sum, the total built up while looping over the array. The closing bracket after the parameter name is missing. It should be function average(nums) {.
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 710–727) and word search (Modules 710–742).
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 total(scores)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →