File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed
Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
22
3+ // Prediction: Error is that address is not an array, so address[0] is undefined.
4+ // Actual output: "My house number is undefined"
5+
36// This code should log out the houseNumber from the address object
47// but it isn't working...
58// Fix anything that isn't working
@@ -12,4 +15,4 @@ const address = {
1215 postcode : "XYZ 123" ,
1316} ;
1417
15- console . log ( `My house number is ${ address [ 0 ] } ` ) ;
18+ console . log ( `My house number is ${ address . houseNumber } ` ) ;
Original file line number Diff line number Diff line change 11// Predict and explain first...
22
3+ // Prediction: The error is that it is trying to iterate over a non-array object.
4+ // Actual output: TypeError: author is not iterable
5+
36// This program attempts to log out all the property values in the object.
47// But it isn't working. Explain why first and then fix the problem
58
@@ -11,6 +14,6 @@ const author = {
1114 alive : true ,
1215} ;
1316
14- for ( const value of author ) {
15- console . log ( value ) ;
17+ for ( const key in author ) {
18+ console . log ( key + ": " + author [ key ] ) ;
1619}
Original file line number Diff line number Diff line change 11// Predict and explain first...
22
3+ // Prediction: The error is that recipe is being treated as a string
4+ // Actual output: bruschetta serves 2 [object Object]
5+
36// This program should log out the title, how many it serves and the ingredients.
47// Each ingredient should be logged on a new line
58// How can you fix it?
@@ -11,5 +14,5 @@ const recipe = {
1114} ;
1215
1316console . log ( `${ recipe . title } serves ${ recipe . serves }
14- ingredients:
15- ${ recipe } `) ;
17+ ingredients:
18+ ${ recipe . ingredients . join ( ", " ) } `) ;
You can’t perform that action at this time.
0 commit comments