Skip to content

Commit 2f702f0

Browse files
authored
Fix recipe logging to show ingredients correctly
Updated recipe logging to display ingredients on separate lines.
1 parent 8eb363e commit 2f702f0

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎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)