Skip to content

Commit 6c481d8

Browse files
committed
Resolve debugging tasks
1 parent de6889c commit 6c481d8

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎Sprint-2/debug/address.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Predict and explain first...
2+
// address is an object, not an array.
3+
// Because it does not have a property named "0", this code will log: "My house number is undefined".
24

35
// This code should log out the houseNumber from the address object
46
// but it isn't working...
@@ -12,4 +14,4 @@ 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.houseNumber}`);

‎Sprint-2/debug/author.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Predict and explain first...
2+
// The author variable is an object. As such, it is not iterable by default.
3+
// Therefore, using a for...of loop on it throws a TypeError.
24

35
// This program attempts to log out all the property values in the object.
46
// But it isn't working. Explain why first and then fix the problem
@@ -11,6 +13,6 @@ const author = {
1113
alive: true,
1214
};
1315

14-
for (const value of author) {
16+
for (const value of Object.values(author)) {
1517
console.log(value);
1618
}

‎Sprint-2/debug/recipe.js‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Predict and explain first...
2+
// The recipe object is interpolated into the template literal (${recipe}).
3+
// During interpolation, JavaScript converts the object to a string.
4+
// Consequently, the object's properties, including the ingredients array, is not displayed.
25

36
// This program should log out the title, how many it serves and the ingredients.
4-
// Each ingredient should be logged on a new line
7+
// Each ingredient should be logged on a new line.
58
// How can you fix it?
69

710
const recipe = {
@@ -10,6 +13,9 @@ const recipe = {
1013
ingredients: ["olive oil", "tomatoes", "salt", "pepper"],
1114
};
1215

13-
console.log(`${recipe.title} serves ${recipe.serves}
14-
ingredients:
15-
${recipe}`);
16+
console.log(`${recipe.title} serves ${recipe.serves}`);
17+
console.log("Ingredients:");
18+
19+
for (const ingredient of recipe.ingredients) {
20+
console.log(ingredient);
21+
}

0 commit comments

Comments
 (0)