File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 1
1
// Predict and explain first...
2
2
3
+ // In order to get access to houseNumber we need use dot notation with name property and object name.
4
+
3
5
// This code should log out the houseNumber from the address object
4
6
// but it isn't working...
5
7
// Fix anything that isn't working
@@ -12,4 +14,5 @@ const address = {
12
14
postcode : "XYZ 123" ,
13
15
} ;
14
16
15
- console . log ( `My house number is ${ address [ 0 ] } ` ) ;
17
+ // 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 1
1
// Predict and explain first...
2
2
3
+ // Firstly I think that I can get access to object values as I usually get to the array elements.
4
+ // But I got error. Now I understood and learnt that to get access to object properties we need special
5
+ // use method Object.keys, Object.values, Object.entries (to access both).
6
+
3
7
// This program attempts to log out all the property values in the object.
4
8
// But it isn't working. Explain why first and then fix the problem
5
9
@@ -11,6 +15,6 @@ const author = {
11
15
alive : true ,
12
16
} ;
13
17
14
- for ( const value of author ) {
18
+ for ( const value of Object . values ( author ) ) {
15
19
console . log ( value ) ;
16
20
}
Original file line number Diff line number Diff line change 1
1
// Predict and explain first...
2
2
3
+ // Here we have nested object, to be precise array under key ingredients.
4
+ // To get access to array we use dot notation with ingredients key. But each ingredient
5
+ // should be on a separate line. That mean that we need loop through this array.
6
+
3
7
// This program should log out the title, how many it serves and the ingredients.
4
8
// Each ingredient should be logged on a new line
5
9
// How can you fix it?
@@ -11,5 +15,11 @@ const recipe = {
11
15
} ;
12
16
13
17
console . log ( `${ recipe . title } serves ${ recipe . serves }
14
- ingredients:
15
- ${ recipe } `) ;
18
+ ingredients: ` ) ;
19
+ for ( const ingredient of recipe . ingredients ) {
20
+ console . log ( `${ ingredient } ` ) ;
21
+ }
22
+
23
+ // console.log(`${recipe.title} serves ${recipe.serves}
24
+ // ingredients:
25
+ // ${ingredient}`);
You can’t perform that action at this time.
0 commit comments