File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -97,16 +97,53 @@ console.log(antonietta.multiplyNums(3,4))
9797// 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
9898// 4. Give each of the objects the ability to speak their names using the this keyword.
9999
100- const parent = { }
101100
102- // Log the parent object's name
103101
104- // Log the child's age
102+ const parent = {
103+ name : "Susan" ,
104+ age : 70 ,
105+ speaks : "My name is " ,
106+ speakUp : function ( ) {
107+ console . log ( `${ this . speaks } ${ this . name } ` ) ;
108+ } ,
109+ child : {
110+ name : "George" ,
111+ age : 50 ,
112+ speaks : "My name is " ,
113+ speakUp : function ( ) {
114+ console . log ( `${ this . speaks } ${ this . name } ` ) ;
115+ } ,
116+ grandchild : {
117+ name : "Sam" ,
118+ age : 30 ,
119+ speaks : "My name is " ,
120+ speakUp : function ( ) {
121+ console . log ( `${ this . speaks } ${ this . name } ` ) ;
122+ } ,
123+ }
124+ }
125+ } ;
126+
105127
106- // Log the name and age of the grandchild
128+
107129
108- // Have the parent speak
130+ parent . speakUp ( ) ;
131+ parent . child . speakUp ( ) ;
132+ parent . child . grandchild . speakUp ( ) ;
109133
134+ // Log the parent object's name
135+ console . log ( parent . name ) ;
136+ // Log the child's age
137+ console . log ( parent . child . age )
138+ // Log the name and age of the grandchild
139+ console . log ( parent . child . grandchild . name , parent . child . grandchild . age )
140+ // Have the parent speak
141+ console . log ( this . speaks + this . name )
110142// Have the child speak
111-
143+ console . log ( ` ${ parent . child . speaks + parent . child . name } !` )
112144// Have the grandchild speak
145+ console . log ( `${ parent . child . grandchild . speaks + parent . child . grandchild . name } ` )
146+
147+ function speakUp ( ) {
148+ console . log ( this . name ) ;
149+ }
You can’t perform that action at this time.
0 commit comments