Question
Suppose you are given the following object that describes a recipe. { idMeal: 52780, strMeal: Potato Gratin with Chicken, strIngredient1: Potatoes, strIngredient2: Onions, strIngredient3: Olive
Suppose you are given the following object that describes a recipe.
{ idMeal: "52780", strMeal: "Potato Gratin with Chicken", strIngredient1: "Potatoes", strIngredient2: "Onions", strIngredient3: "Olive Oil", strIngredient4: "Chicken Stock", strIngredient5: null, strIngredient6: "", strIngredient7: "Chicken Breasts", strIngredient8: "", strIngredient9: "Spinach", strIngredient10: null, strIngredient11: "", strIngredient12: "", strIngredient13: "", strIngredient14: "Bacon", strIngredient15: "", strIngredient16: null, strIngredient17: "Parmesan", strIngredient18: "Peas", strIngredient19: null, strIngredient20: "Creme Fraiche", dateModified: null, price: 13.99 }
Write a general purpose Javascript function that accepts an object (say recipe) and prints the ingredients to the console, with each ingredient separated by a whitespace. You can write it as a script and then run it on your browser
Keep in mind, we dont want to print the null or empty ingredients. Also, your function should be flexible enough to handle ANY object in the above format i.e. if I test your code by passing in an recipe object that has just 5 valid ingredients and the rest are null or empty, it should still work.
You can assume all recipe objects will have 20 fields for ingredients, but not all of them will be populated.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started