← ACARA Digital Technologies Years 9–10

Methods with parameters and return values (JavaScript)

A class method takes a parameter (amount) and uses return to give back a value worked out from the object's properties, such as the new balance.

Understanding Methods with parameters and return values (JavaScript) in ACARA Digital Technologies Years 9–10

What it does: extra is the parameter, this.points is the property, and return gives back the calculated total. Inside a class method, the object's properties are reached with this. Plain width and height would be undefined variables. Template literals need backticks. Single quotes treat ${...} as plain text, so the values would not be inserted. A parameter is a placeholder. The value (argument) you put in the brackets when you call the method fills it in. console.log only prints to the console. To use the result elsewhere in your program, the method must return it. The method adds 20 to this.balance, making it 120, then returns this.balance. It returns the new balance, not the amount passed in.

Common mistakes: Inside a method, the object's property must be reached with this. Without this, balance is treated as a separate variable and causes a ReferenceError. It should be this.balance += amount;. A method needs parentheses after its name, even when it takes no parameters. It should be getArea() {.

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 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.

Learning
Duo
Which deposit method adds the amount AND gives the new balance back to the caller?
deposit(amount) { this.balance += amount; return this.balance; }deposit(amount) { this.balance += amount; }
Matches
deposit(amount) { balance += amount; return balance; }
↓
The properties are missing this. so the method looks for a variable called balance instead of the object's property. It should be this.balance.
Applying
Meanings
Term
deposit(amount) { this.balance += amount; return this.balance; }
Meaning
A class method takes a parameter (amount) and uses return to give back a value worked out from the object's properties, such as the new balance.
Practice
class Account {
Testing
Gaps
this.balance; }
Check Answer
Spots
2 deposit(amount) {
3 balance += amount;

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

The 'Parrotfish' badge — Function Builder, 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. Which deposit method adds the amount AND gives the new balance back to the caller?
A. deposit(amount) { this.balance += amount; }
B. deposit(amount) { this.balance += amount; return this.balance; } ✓
Without a return statement the method gives back undefined. The return line sends the new balance to whoever called deposit.
2. Which getArea() method correctly returns the area of a Rectangle object?
A. getArea() { return this.width * this.height; } ✓
B. getArea() { return width * height; }
Inside a class method, the object's properties are reached with this. Plain width and height would be undefined variables.
3. Which line calls deposit with 50 and saves the value it returns?
A. const newBalance = account.deposit(50); ✓
B. const newBalance = deposit(50);
A method belongs to an object, so you call it with dot notation: account.deposit(50). The returned value can then be stored in a variable.
4. Which method returns a string such as 'Ava has 120 points' using a template literal?
A. describe() { return ${this.name} has ${this.balance} points; } ✓
B. describe() { return '${this.name} has ${this.balance} points'; }
Template literals need backticks. Single quotes treat ${...} as plain text, so the values would not be inserted.
5. Where does the parameter amount in deposit(amount) get its value?
A. It is a property that every object stores automatically
B. From the argument passed in when the method is called, e.g. deposit(50) ✓
A parameter is a placeholder. The value (argument) you put in the brackets when you call the method fills it in.

Match the Pairs

deposit(amount) { this.balance += amount; return this.balance; } → A method that takes an amount, adds it to the object's balance and returns the new balance.
getArea() { return this.width * this.height; } → A method with no parameters that returns a number worked out from the object's width and height properties.
A method can take a parameter and use it with a property to work out a value to return. → addBonus(extra) { return this.points + extra; }
A method can return a string built with a template literal using the object's properties. → describe() { return `${this.name} has $${this.balance}`; }
deposit(amount) { balance += amount; return balance; } → The properties are missing this. so the method looks for a variable called balance instead of the object's property. It should be this.balance.
getArea() { this.width * this.height; } → The method never uses return, so the calculated area is thrown away and the caller gets undefined. It should be return this.width * this.height;

Key Term

deposit(amount) { this.balance += amount; return this.balance; }
A class method takes a parameter (amount) and uses return to give back a value worked out from the object's properties, such as the new balance.

Fill in the Blanks

1. deposit(amount) { this.balance += amount; return this.balance; }
Hint: Type the keyword that sends the new balance back to the code that called the method.
2. deposit(amount) { this.balance += amount; return this.balance; }
Hint: Type the operator that adds the parameter's value onto the balance already stored in the object.
3. getArea() { return this.width * this.height; }
Hint: Type the arithmetic operator that works out the area of a rectangle from its two sides.
4. getInfo() { return `${this.name} has ${this.points}`; }
Hint: Type the keyword that refers to the current object, so the method can read its own properties.
5. const acc = new Account("Sam", 50); const newBal = acc.deposit(20); console.log(newBal);
Hint: Type the name of the method that takes an amount of money and returns the updated balance.

Spot the Error

Question 1
A class Account {
B deposit(amount) {
C balance += amount;
D return this.balance;
E }
F }
Line C — Inside a method, the object's property must be reached with this. Without this, balance is treated as a separate variable and causes a ReferenceError. It should be this.balance += amount;
Question 2
A getArea {
B return this.side ** 2;
C }
Line A — A method needs parentheses after its name, even when it takes no parameters. It should be getArea() {
Question 3
A greet() {
B return 'Hi ${this.name}!';
C }
Line B — Template literals must use backticks. With single quotes, ${this.name} is not replaced and the text is returned as-is. It should be return `Hi ${this.name}!`;
Question 4
A const acc = new Account(50);
B const t = acc.deposit;
C console.log(t);
Line B — Without parentheses the method is never called, so t holds the function instead of the returned balance. It should be const t = acc.deposit(20);
Question 5
A class Wallet {
B spend(amount) {
C this.cash -= amount;
D return amount;
E }
F }
Line D — This returns the parameter that was passed in, not the new value worked out from the object's property. It should be return this.cash;

Student with a class code? Join your class →