Skip to content

Commit 2488a71

Browse files
committed
format recipe output to log ingredients on new lines
1 parent 6de1246 commit 2488a71

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

‎Sprint-2/debug/recipe.js‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Predict and explain first...
2+
//in the template literal the ${recipe}`is referring to the whole object, we want the items in the ingredients of the recipe object, listed line by 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
@@ -10,6 +11,20 @@ const recipe = {
1011
ingredients: ["olive oil", "tomatoes", "salt", "pepper"],
1112
};
1213

13-
console.log(`${recipe.title} serves ${recipe.serves}
14-
ingredients:
15-
${recipe}`);
14+
// const recipeKeys = Object.keys(recipe)
15+
// // console.log(recipeKeys)
16+
17+
const recipeValues = Object.values(recipe);
18+
// ["bruschetta", 2, ["olive oil", "tomatoes", "salt", "pepper"]]
19+
20+
const ingredients = recipeValues.slice(-1)[0];
21+
// ["olive oil","tomatoes","salt","pepper"]
22+
23+
//create a function to log line by line the elements of an array
24+
function logItemised(items) {
25+
return items.join("\n");
26+
}
27+
28+
console.log(
29+
`${recipe.title} serves ${recipe.serves}${"\n"}ingredients:${"\n"}${logItemised(ingredients)}`
30+
);

0 commit comments

Comments
 (0)