forum

Home / DeveloperSection / Forums / javaScript nested for-in and for loops

javaScript nested for-in and for loops

abhi mohan156926-Aug-2017
I am a beginner in javaScript. Can someone please help me with the below problem ?

I want to write a code with for in and for loop so that :

It will loop through all recipes in the recipeBook, and print the recipe name followed by its ingredients list. For example, the output for the chocolate cake might look as follows:
Chocolate Cake:
- 1 3/4 cup flour
- 1/2 cup cocoa
- 2 tsp baking powder
- 1 cup Chelsea White Sugar
- 125g butter
- 2 Tbsp Chelsea Golden Syrup
- 2 eggs
- 1 1/2 cup milk
- 2 tsp baking soda
- 1 tsp vanilla essence

Code to add "chocolate cake" to the recipe book could look like this:

recipeBook["Chocolate Cake"] = [ 
  "1 3/4 cup flour",
  "1/2 cup cocoa",
  "2 tsp baking powder",
  "1 cup sugar",
  "125g butter",
  "2 Tbsp golden syrup",
  "2 eggs",
  "1 1/2 cup milk",
  "2 tsp baking soda",
  "1 tsp vanilla essence"
];

Updated on 07-Jun-2018

Can you answer this question?


Answer

1 Answers

Liked By