Skip to content

Commit ee5bf8b

Browse files
finished object stretch
1 parent 0efbcbf commit ee5bf8b

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

‎assignments/objects.js‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ kennan.speak = function() {
6969
return `Hello, my name is Kennan!`;
7070
}
7171

72+
console.log(kennan.speak());
73+
7274
// Antonietta loves math, give her the ability to multiply two numbers together and return the product. Use the console.log provided as a hint.
7375
//console.log(antonietta.multiplyNums(3,4));
7476

@@ -77,16 +79,41 @@ antonietta.multiplyNums = function(num1, num2) {
7779
return `My name is Antonietta. The product is ${product}`;
7880
}
7981

82+
console.log(antonietta.multiplyNums(3,4))
8083
// === Great work! === Head over to the the arrays.js file or take a look at the stretch challenge
8184

8285
// ==== Stretch Challenge: Nested Objects and the this keyword ====
8386

8487
// 1. Create a parent object with properties for name and age. Make the name Susan and the age 70.
88+
89+
8590
// 2. Nest a child object in the parent object with name and age as well. The name will be George and the age will be 50.
8691
// 3. Nest a grandchild object in the child object with properties for name and age. The name will be Sam and the age will be 30
8792
// 4. Give each of the objects the ability to speak their names using the this keyword.
8893

89-
const parent = {}
94+
const parent = {
95+
name: 'Susan',
96+
age: 70,
97+
child: {
98+
name: 'George',
99+
age: 50,
100+
grandchild: {
101+
name: 'Sam',
102+
age: 30
103+
}
104+
}
105+
}
106+
107+
function sayHello() {
108+
`Hello! My name is ${this.name}`
109+
};
110+
111+
112+
parent.sayHello = sayHello();
113+
114+
child.sayHello = sayHello();
115+
116+
grandchild.sayHello = sayHello();
90117

91118
// Log the parent object's name
92119

0 commit comments

Comments
 (0)