1+ const recipes = [ ] ;
2+
3+ const recipe1 = {
4+ name : "Spaghetti Carbonara" ,
5+ ingredients : [ "spaghetti" , "Parmesan cheese" , "pancetta" , "black pepper" ] ,
6+ cookingTime : 22 ,
7+ totalIngredients : null ,
8+ difficultyLevel : ""
9+ } ;
10+
11+ const recipe2 = {
12+ name : "Chicken Curry" ,
13+ ingredients : [ "chicken breast" , "coconut milk" , "curry powder" , "onion" , "garlic" ] ,
14+ cookingTime : 42 ,
15+ totalIngredients : null ,
16+ difficultyLevel : ""
17+ } ;
18+
19+ const recipe3 = {
20+ name : "Vegetable Stir Fry" ,
21+ ingredients : [ "broccoli" , "carrot" , "bell pepper" ] ,
22+ cookingTime : 15 ,
23+ totalIngredients : null ,
24+ difficultyLevel : ""
25+ } ;
26+
27+ recipes . push ( recipe1 , recipe2 , recipe3 ) ;
28+
29+ function getTotalIngredients ( ingredients ) {
30+ return ingredients . length ;
31+ }
32+
33+ function getDifficultyLevel ( cookingTime ) {
34+ if ( cookingTime <= 30 ) {
35+ return "easy" ;
36+ } else if ( cookingTime <= 60 ) {
37+ return "medium" ;
38+ } else {
39+ return "hard" ;
40+ }
41+ }
42+
43+ const recipe1TotalIngredients = getTotalIngredients ( recipe1 . ingredients ) ;
44+ console . log ( recipe1TotalIngredients ) ;
45+
46+ const recipe1DifficultyLevel = getDifficultyLevel ( recipe1 . cookingTime ) ;
47+ console . log ( recipe1DifficultyLevel ) ;
48+
49+ recipe1 . totalIngredients = getTotalIngredients ( recipe1 . ingredients ) ;
50+ recipe1 . difficultyLevel = getDifficultyLevel ( recipe1 . cookingTime ) ;
51+
52+ recipe2 . totalIngredients = getTotalIngredients ( recipe2 . ingredients ) ;
53+ recipe2 . difficultyLevel = getDifficultyLevel ( recipe2 . cookingTime ) ;
54+
55+ recipe3 . totalIngredients = getTotalIngredients ( recipe3 . ingredients ) ;
56+ recipe3 . difficultyLevel = getDifficultyLevel ( recipe3 . cookingTime ) ;
57+
58+ console . log ( recipes ) ;
0 commit comments