Skip to content

Commit 70aa131

Browse files
committed
Stretch goals for objects compleated
1 parent f1884a1 commit 70aa131

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

assignments/objects.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,45 @@ console.log(intern4.multiplyNums(3, 4));
9292
// 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
9393
// 4. Give each of the objects the ability to speak their names using the this keyword.
9494

95-
const parent = {};
95+
const parent = {
96+
name: 'Susan',
97+
age: 70,
98+
speak: () => {
99+
console.log('This is the parent speaking');
100+
},
101+
102+
child: {
103+
name: 'George',
104+
age: 50,
105+
speak: () => {
106+
console.log('This is the child speaking');
107+
},
108+
109+
grandChild: {
110+
name: 'Sam',
111+
age: 30,
112+
speak: () => {
113+
console.log('This is the grandchild speaking');
114+
}
115+
}
116+
}
117+
};
96118

97119
// Log the parent object's name
120+
console.log(parent.name);
98121

99122
// Log the child's age
123+
console.log(parent.child.age);
100124

101125
// Log the name and age of the grandchild
126+
console.log(parent.child.grandChild.age);
102127

103128
// Have the parent speak
129+
console.log(parent.speak());
104130

105131
// Have the child speak
132+
console.log(parent.child.speak());
106133

107134
// Have the grandchild speak
135+
136+
console.log(parent.child.grandChild.speak());

0 commit comments

Comments
 (0)