Skip to content

Commit 391bd80

Browse files
committed
Fix recipe logging to display ingredients correctly
1 parent b6eb718 commit 391bd80

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

‎Sprint-2/debug/recipe.js‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// Predict and explain first...
22

3+
/* PREDICTION - it would print out the name, how many it serves perfectly but wouldn't work well for the ingredients.
4+
5+
EXPLANATION
6+
Printing the whole object instead of ingredients: The template literal uses ${recipe} at the end. When JavaScript tries to insert an object into a template literal string,
7+
it calls .toString() on the object, which results in the generic string "[object Object]" instead of showing its properties or the array inside. */
8+
39
// This program should log out the title, how many it serves and the ingredients.
410
// Each ingredient should be logged on a new line
511
// How can you fix it?
@@ -10,6 +16,5 @@ const recipe = {
1016
ingredients: ["olive oil", "tomatoes", "salt", "pepper"],
1117
};
1218

13-
console.log(`${recipe.title} serves ${recipe.serves}
14-
ingredients:
15-
${recipe}`);
19+
console.log(`${recipe.title} serves ${recipe.serves}\n
20+
ingredients:${recipe.ingredients.join("\n")}`);

0 commit comments

Comments
 (0)