← ACARA Digital Technologies Years 9–10

Modifying an existing class

Modifying a class: add or change a constructor parameter, property or method, then update every new call that creates its objects and re-run your tests.

Understanding Modifying an existing class in ACARA Digital Technologies Years 9–10

What it does: The new call passes both arguments, so it matches the updated constructor and the object gets a score. A method is added inside the class and can then be used on objects like p1.addPoints(5), which you should check by re-running your tests. Old calls leave the new parameter undefined, so update every new call to pass a value. The property needs this. in front of it. Without this.score, no property is stored on the object. Methods sit inside the class body beside the constructor, not inside it. JavaScript does not rename other uses. Old .score code would now give undefined.

Common mistakes: The new score property was added to the constructor body, but the parameter was not added. 'score' is undefined, so the constructor should be constructor(name, score). The new age property is being given the name parameter. It should store the age parameter: this.age = age;.

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 743–781) and word search (Modules 743–809).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
You add a new parameter to a class constructor. What else must you update?
Nothing, old new calls keep working automaticallyEvery new call that creates objects from the class
Matches
constructor(name, score) { this.name = name; } let p = new Player('Ava', 10);
↓
The score parameter was added but never stored with this.score = score, so the object has no score property.
Applying
Meanings
Term
this.score = score;
Meaning
Modifying a class: add or change a constructor parameter, property or method, then update every new call that creates its objects and re-run your tests.
Practice
class Player {
Testing
Gaps
constructor(name, ) {
Check Answer
Spots
1class Player {
2 constructor(name) {

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

The 'Kangaroo Rat' badge — Speed Typer, 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 add a new parameter to a class constructor. What else must you update?
A. Nothing, old new calls keep working automatically
B. Every new call that creates objects from the class ✓
Old calls leave the new parameter undefined, so update every new call to pass a value.
2. Which constructor correctly adds a score property to a Player class?
A. constructor(name, score) { this.name = name; this.score = score; } ✓
B. constructor(name, score) { this.name = name; score = score; }
The property needs this. in front of it. Without this.score, no property is stored on the object.
3. A Player class now has constructor(name, score). Which call matches it?
A. new Player('Ava', 10) ✓
B. new Player('Ava')
The second call leaves score undefined. Every new call needs a value for each new parameter.
4. You add a new method to a class. Where does it go?
A. Inside the constructor, after the this lines
B. Inside the class braces, next to the constructor ✓
Methods sit inside the class body beside the constructor, not inside it.
5. You changed a class. What should you do before you trust it again?
A. Re-run your tests and check they still pass ✓
B. Skip the tests because the change was small
Even a small change can break code that used to work, so re-run your tests.

Match the Pairs

constructor(name, score) { → The constructor now takes a new parameter, score, so every new call must be updated to pass it in.
this.score = score; → Adds a new property to the class by saving the score parameter on each object that is created.
After adding a score parameter to the constructor, update the code that creates objects so it passes the new value. → let p1 = new Player('Ava', 10);
Adding a new method to a class means writing it inside the class body, then calling it on an object. → addPoints(n) { this.score += n; }
constructor(name, score) { this.name = name; } let p = new Player('Ava', 10); → The score parameter was added but never stored with this.score = score, so the object has no score property.
constructor(name, score) { ... } let p = new Player('Ava'); → The constructor was changed to need two values, but this new call was not updated, so score is undefined.

Key Term

this.score = score;
Modifying a class: add or change a constructor parameter, property or method, then update every new call that creates its objects and re-run your tests.

Fill in the Blanks

1. constructor(name, score) { this.name = name; this.score = score;
Hint: Type the new parameter name added to the constructor so each object can receive this value
2. constructor(name, score) { this.name = name; this.score = score;
Hint: Type the name of the new property being stored on the object
3. addPoints(n) { this.score += n; }
Hint: Type the operator that adds a value onto the existing property and saves the result
4. const p1 = new Player("Ava", 10);
Hint: Type the keyword that creates an object from the class, with the call updated for the new parameter
5. const p = new Player("Ava", 10); p.addPoints(5); console.assert(p.score === 15);
Hint: Type the strict equality operator used to re-run a test after changing the class

Spot the Error

Question 1
A class Player {
B constructor(name) {
C this.name = name;
D this.score = score;
E }
F }
Line B — The new score property was added to the constructor body, but the parameter was not added. 'score' is undefined, so the constructor should be constructor(name, score).
Question 2
A class Pet {
B constructor(name, age) {
C this.name = name;
D this.age = name;
E }
F }
Line D — The new age property is being given the name parameter. It should store the age parameter: this.age = age;
Question 3
A class Player {
B addPoints(n) {
C this.score + n;
D }
E }
Line C — The new method works out score + n but never saves it. To change the property, use this.score += n;
Question 4
A let a = new Car("Kia");
B let b = new Car("VW", 2018);
C console.log(a.year);
D console.log(b.year);
Line A — The constructor now takes a year, so every new call must be updated. This call is missing 2020, so a.year would be undefined.
Question 5
A let p = new Player("Ana", 0);
B p.addPoints(5);
C p.addPoints(10);
D console.assert(p.score = 15);
Line D — A single = assigns 15 to score instead of comparing, so the test always passes. Use == or === to compare: p.score == 15.

Student with a class code? Join your class →