← ACARA Digital Technologies Years 7–8

Modifying an existing JavaScript program

Read the code and predict what it does, change one small part (a value, condition or message), run it, then compare the result with your prediction.

Understanding Modifying an existing JavaScript program in ACARA Digital Technologies Years 7–8

What it does: An extra else if adds a new branch to the existing program without rewriting the parts that already work. Editing one part of a loop, such as the 3 in i < 3 changed to 5, lets you predict how many lines print, run it and compare. Read and predict first. Then you can tell whether your change did what you expected. Changing one thing at a time means that if something breaks, you know which change caused it. Running the program and comparing the result with your prediction shows whether you understood the code. A copy lets you go back to the working version if your changes cause bugs.

Common mistakes: The change to the value uses the wrong operator. '--' is not valid between two values, so the program will not run. It should be 'lives = lives - 1;'. The message uses the number 1 instead of the loop counter i, so every lap prints 'Lap 1'. It should be console.log("Lap " + i);.

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 624–634) 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
You are given a working JavaScript program and asked to change it. What should you do first?
Read the code and predict what it will doDelete lines until it looks shorter
Matches
// changed the loop limit, the message AND the score all at once let limit = 10; let msg = "Go!"; let score = 100;
↓
Too many changes were made at once, so if the program breaks you cannot tell which change caused it
Applying
Meanings
Term
predict, change, run
Meaning
Read the code and predict what it does, change one small part (a value, condition or message), run it, then compare the result with your prediction.
Practice
for (let i = 1; i <= 5; i++) {
Testing
Gaps
for (let i = 0; i < ; i++) {
Check Answer
Spots
1let lives = 3;
2lives = lives -- 1;

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

The 'Dumbo Octopus' badge — Module Maker, 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. You are given a working JavaScript program and asked to change it. What should you do first?
A. Delete lines until it looks shorter
B. Read the code and predict what it will do ✓
Read and predict first. Then you can tell whether your change did what you expected.
2. Which is the better way to modify a program?
A. Change one small part, then run it ✓
B. Change five parts, then run it once
Changing one thing at a time means that if something breaks, you know which change caused it.
3. You change the loop in for (let i = 1; i <= 3; i++) to i <= 5. What should you do next?
A. Run it and compare the output with your prediction ✓
B. Assume it works and move on without running
Running the program and comparing the result with your prediction shows whether you understood the code.
4. Before editing a working program, what is a smart way to protect it?
A. Keep a copy of the original ✓
B. Overwrite it and hope you remember it
A copy lets you go back to the working version if your changes cause bugs.
5. A program prints 'Hello, Sam!'. You change the message text to 'Welcome, Sam!'. What kind of change is this?
A. Adding a brand new loop
B. A small change to a message ✓
Changing a value, condition or message is a small, safe way to start modifying code.

Match the Pairs

let lives = 3; // try 5 instead → Change one small value, then run the program again to see what is different
// let score = 0; let score = 10; → Keep a copy of the original line as a comment before you change it
Add a new branch to an existing if statement so the program handles one more case → else if (score >= 50) { console.log("Pass"); }
Change a loop's condition, then run it and compare the output with your prediction → for (let i = 0; i < 5; i++) { console.log(i); }
// changed the loop limit, the message AND the score all at once let limit = 10; let msg = "Go!"; let score = 100; → Too many changes were made at once, so if the program breaks you cannot tell which change caused it
let total = 0; total += 5; console.log(total); // I did not predict the output, just ran it → The student ran the program without predicting the result first, so there is nothing to compare against

Key Term

predict, change, run
Read the code and predict what it does, change one small part (a value, condition or message), run it, then compare the result with your prediction.

Fill in the Blanks

1. // change: repeat 5 times for (let i = 0; i < 5; i++) { console.log("Go!");
Hint: Type the number of repeats that the comment asks for
2. if (score >= 90) { grade = "A"; } else if (score >= 80) { grade = "B"; } else { grade = "C"; }
Hint: Type the keywords that add a new branch between the if and the final else
3. let score = 10; const original = score; score = 20;
Hint: Type the variable name whose value is being saved as a copy before it is changed
4. // change: 18 year olds can now enter if (age >= 18) console.log("Enter");
Hint: Type the comparison operator so that the boundary age is included
5. let total = 0; for (let i = 1; i <= 3; i++) total += i; console.log(total);
Hint: Type the variable to print so you can compare the result with your prediction

Spot the Error

Question 1
A let lives = 3;
B lives = lives -- 1;
C console.log(lives);
D // Predict: 2
Line B — The change to the value uses the wrong operator. '--' is not valid between two values, so the program will not run. It should be 'lives = lives - 1;'.
Question 2
A // Changed from 3 laps to 5
B for (let i = 1; i <= 5; i++) {
C console.log("Lap " + 1);
D }
Line C — The message uses the number 1 instead of the loop counter i, so every lap prints 'Lap 1'. It should be console.log("Lap " + i);
Question 3
A let temp = 31;
B if (temp > 30 {
C console.log("Hot");
D } else if (temp > 20) {
E console.log("Warm");
F }
Line B — The closing bracket of the condition is missing, so there is a syntax error. It should be 'if (temp > 30) {'.
Question 4
A let mark = 72;
B let grade = "C";
C if (mark = 80) {
D grade = "B";
E }
F console.log(grade);
Line C — A single = assigns a value instead of comparing. The changed condition should use >= to compare: 'if (mark >= 80) {'.
Question 5
A let price = 20;
B let original = price;
C price = price + 5;
D console.log(orignal);
E console.log(price);
Line D — The name of the copy is misspelled, so JavaScript throws a ReferenceError. It should be console.log(original); to print the saved copy.

Student with a class code? Join your class →