Skip to content

Commit 3cd7722

Browse files
authored
Fix recipe output formatting in console log
Updated console log to display ingredients correctly.
1 parent 8e11a64 commit 3cd7722

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎Sprint-2/debug/recipe.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,19 @@ const recipe = {
1313
console.log(`${recipe.title} serves ${recipe.serves}
1414
ingredients:
1515
${recipe}`);
16+
17+
//Prediction:
18+
//output will be, [object Object]. Because recipe is an object, when js converts objects to a string (template literals can only insert strings) it calls on toString() method, which
19+
//by default returns [Object Object]. We can fix this code by using join(\n) method.
20+
21+
//fixed code:
22+
23+
const recipe = {
24+
title: "bruschetta",
25+
serves: 2,
26+
ingredients: ["olive oil", "tomatoes", "salt", "pepper"],
27+
};
28+
29+
console.log(`${recipe.title} serves ${recipe.serves}
30+
Ingredients:
31+
${recipe.ingredients.join("\n")}`);

0 commit comments

Comments
 (0)