Skip to content

Commit f21c96e

Browse files
committed
predicted the result of each file before fixing them
1 parent 5007c4b commit f21c96e

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Sprint-2/debug/address.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Predict and explain first...
2+
//the original code is using the wrong notation to access our object this will return undefined as we do not have a 0 property.
23

34
// This code should log out the houseNumber from the address object
45
// but it isn't working...
56
// Fix anything that isn't working
7+
//fixed it by puting "houseNumber" in the square brackets.
68

79
const address = {
810
houseNumber: 42,
@@ -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,7 +1,9 @@
11
// Predict and explain first...
2+
//the method for of is an array method and it would be looking for an indexed list of items rather than a key value pair so an error will be thrown since we are using an object.
23

34
// This program attempts to log out all the property values in the object.
45
// But it isn't working. Explain why first and then fix the problem
6+
//i can fix this by changing for ... of to for ... in.
57

68
const author = {
79
firstName: "Zadie",
@@ -11,6 +13,6 @@ const author = {
1113
alive: true,
1214
};
1315

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

Sprint-2/debug/recipe.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
// Predict and explain first...
2+
//it will display the title and number of people it serves on one line then the whole recipe on the next line
23

34
// This program should log out the title, how many it serves and the ingredients.
45
// Each ingredient should be logged on a new line
56
// How can you fix it?
7+
//by using the string literal to ensure multiple lines, then having the title on the first line, the number served on the next line and ingredients on the third line. using the dot notation to access the properties needed.
68

79
const recipe = {
810
title: "bruschetta",
911
serves: 2,
1012
ingredients: ["olive oil", "tomatoes", "salt", "pepper"],
1113
};
1214

13-
console.log(`${recipe.title} serves ${recipe.serves}
14-
ingredients:
15-
${recipe}`);
15+
console.log(`${recipe.title} serves ${recipe.serves}
16+
ingredients: ${recipe.ingredients[0]}
17+
${recipe.ingredients[1]}
18+
${recipe.ingredients[2]}
19+
${recipe.ingredients[3]}`);

0 commit comments

Comments
 (0)