Class, object, property and method

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Class, object, property and method

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. In class Dog, which statement is correct?
A Rex is the blueprint and Dog is one object made from it
B Dog is the blueprint and Rex is one object made from it
2. Which one is a property of a Dog object?
A name
B bark()
3. Which one is a method of a Dog object?
A bark()
B age
4. How many Dog objects can you make from one Dog class?
A Only one, because a class makes a single object
B As many as you need, such as Rex and Bella
5. Which sentence matches the idea of properties and methods?
A Properties are nouns that hold data and methods are verbs that act
B Properties are verbs that act and methods are nouns that hold data

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1class Dog { } AThe new keyword is missing, so no object is made from the class. It should be new Dog("Rex").
2let rex = new Dog("Rex"); Bbark is a method of a dog object, not of the class blueprint. Make an object like rex first, then call rex.bark().
3A property holds data about an object, like a noun (the dog's name) CA blueprint that describes what every dog will have and do
4A method is an action an object can do, like a verb (bark) Dconsole.log(rex.name);
5Dog.bark(); Erex.bark();
6let rex = Dog("Rex"); FMakes one object, the dog Rex, from the Dog blueprint

Definitions

class Dog

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
_____ Dog { bark() { console.log("Woof!"); } }
2.
const rex = new ___("Rex");
3.
const rex = new Dog("Rex"); console.log(rex.____);
4.
const rex = new Dog("Rex"); rex.____();
5.
constructor(name) { ____.name = name; }

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A class Dog {
B constructor(name) {
C name = name;
D }
E }
Question 2
A class Dog {
B bark() {
C console.log('Woof!';
D }
E }
Question 3
A class Dog {
B constructor(name, age) {
C this.name = name;
D this.age = name;
E }
F }
Question 4
A class Dog {
B function bark() {
C return 'Woof!';
D }
E }
Question 5
A class Dog {
B construct(name) {
C this.name = name;
D }
E }

Answer Key

Class, object, property and method
Section A: Quick Questions
Q1
B — Dog is the blueprint and Rex is one object made from it
Q2
A — name
Q3
A — bark()
Q4
B — As many as you need, such as Rex and Bella
Q5
A — Properties are nouns that hold data and methods are verbs that act
Section B: Match the Pairs
Q1
class Dog { } → A blueprint that describes what every dog will have and do
Q2
let rex = new Dog("Rex"); → Makes one object, the dog Rex, from the Dog blueprint
Q3
A property holds data about an object, like a noun (the dog's name) → console.log(rex.name);
Q4
A method is an action an object can do, like a verb (bark) → rex.bark();
Q5
Dog.bark(); → bark is a method of a dog object, not of the class blueprint. Make an object like rex first, then call rex.bark().
Q6
let rex = Dog("Rex"); → The new keyword is missing, so no object is made from the class. It should be new Dog("Rex").
Section C: Definitions
Q1
class Dog — A blueprint for dogs. An object like Rex is made from it. Properties are its data (nouns like name) and methods are its actions (verbs like bark).
Section D: Fill in the Blanks
Q1
class Dog { bark() { console.log("Woof!"); } }
Q2
const rex = new Dog("Rex");
Q3
const rex = new Dog("Rex"); console.log(rex.name);
Q4
const rex = new Dog("Rex"); rex.bark();
Q5
constructor(name) { this.name = name; }
Section E: Spot the Error
Q1
C — A property belongs to the object, so it must be set with this. The line should be this.name = name; otherwise the dog never gets a name property.
Q2
C — The closing bracket of console.log is missing. The method body should say console.log('Woof!');
Q3
D — The age property is being given the name value. It should be this.age = age; so each property stores its own data.
Q4
B — Methods inside a class are written without the function keyword. The line should be bark() {
Q5
B — The special method that builds each object must be called constructor, not construct. It should be constructor(name) {