Modifying an existing JavaScript program
Read the code and predict its output, change one small part at a time, then re-run your tests after each change to check that nothing else broke.
Understanding Modifying an existing JavaScript program in ACARA Digital Technologies Years 9–10
What it does: A console.assert test can be run again after every change to confirm the function still gives the expected result. Adding a parameter such as greeting changes the function in one small, clear way. Reading the code and predicting its output first helps you understand what it does before you change anything. If you change one thing at a time, you know which change caused a bug if something breaks. Small steps make bugs easier to find because only one thing has changed since the tests last passed. Extra parameters go inside the brackets, separated by commas. A change in one place can break something somewhere else, so re-run the earlier tests after each change.
Common mistakes: JavaScript is case-sensitive. The variable is called sum, so Sum causes a ReferenceError. After a change, re-run the code to catch slips like this. It should be return sum;. The prediction says the output should be 15. Subtracting 5 would print 5. When you change code, check it against your prediction. It should be score = score + 5;.
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 728–742) 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
modify codeFill in the Blanks
Spot the Error
Student with a class code? Join your class →