Skip to content

Commit 254f0b4

Browse files
committed
Completed all exercises in debug directory
1 parent cfd674c commit 254f0b4

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

Sprint-2/debug/address.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
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}`);

Sprint-2/debug/author.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
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
}

Sprint-2/debug/recipe.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
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

1316
console.log(`${recipe.title} serves ${recipe.serves}
14-
ingredients:
15-
${recipe}`);
17+
ingredients:
18+
${recipe.ingredients.join(", ")}`);

0 commit comments

Comments
 (0)