You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-2/debug/address.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
// Predict and explain first...
2
-
2
+
// The address variable is an object literal containing key–value pairs separated by commas. The code originally tries to access address[0], which would only work if the data were in an array. Since address is an object and not an array, there is no index 0, so it returns undefined. To fix the problem we must access the property using its key, for example address.houseNumber.
3
3
// This code should log out the houseNumber from the address object
4
4
// but it isn't working...
5
5
// Fix anything that isn't working
@@ -12,4 +12,4 @@ const address = {
12
12
postcode: "XYZ 123",
13
13
};
14
14
15
-
console.log(`My house number is ${address[0]}`);
15
+
console.log(`My house number is ${address.houseNumber}`);
Copy file name to clipboardExpand all lines: Sprint-2/debug/author.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
// Predict and explain first...
2
-
2
+
// The program does not work because for...of can only be used on iterable objects such as arrays or strings. The author variable is an object, which is not iterable by default. To fix the problem we can use Object.values(author) to convert the object values into an iterable array and then loop through them.
3
3
// This program attempts to log out all the property values in the object.
4
4
// But it isn't working. Explain why first and then fix the problem
Copy file name to clipboardExpand all lines: Sprint-2/debug/recipe.js
+6-2Lines changed: 6 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
// Predict and explain first...
2
-
2
+
// The code does not work because ${recipe} prints the entire object rather than the ingredients array. To display each ingredient on a new line, we need to loop through recipe.ingredients, which is an array. Using a for...of loop allows us to print each ingredient individually.
3
3
// This program should log out the title, how many it serves and the ingredients.
0 commit comments