Skip to content

Commit 355bdc4

Browse files
committed
debug tasks
1 parent 0abc6d8 commit 355bdc4

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Sprint-2/debug/address.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Predict and explain first...
22

3+
// In order to get access to houseNumber we need use dot notation with name property and object name.
4+
35
// This code should log out the houseNumber from the address object
46
// but it isn't working...
57
// Fix anything that isn't working
@@ -12,4 +14,5 @@ const address = {
1214
postcode: "XYZ 123",
1315
};
1416

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}`);

Sprint-2/debug/author.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// Predict and explain first...
22

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+
37
// This program attempts to log out all the property values in the object.
48
// But it isn't working. Explain why first and then fix the problem
59

@@ -11,6 +15,6 @@ const author = {
1115
alive: true,
1216
};
1317

14-
for (const value of author) {
18+
for (const value of Object.values(author)) {
1519
console.log(value);
1620
}

Sprint-2/debug/recipe.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// Predict and explain first...
22

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+
37
// This program should log out the title, how many it serves and the ingredients.
48
// Each ingredient should be logged on a new line
59
// How can you fix it?
@@ -11,5 +15,11 @@ const recipe = {
1115
};
1216

1317
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}`);

0 commit comments

Comments
 (0)