@@ -2,11 +2,11 @@ const input = require('readline-sync');
2
2
3
3
// Part A: #1 Populate these arrays
4
4
5
- let protein = [ ] ;
6
- let grains = [ ] ;
7
- let veggies = [ ] ;
8
- let beverages = [ ] ;
9
- let desserts = [ ] ;
5
+ let protein = [ 'chicken' , 'pork' , 'tofu' , 'beef' , 'fish' , 'beans' ] ;
6
+ let grains = [ 'rice' , 'pasta' , 'corn' , 'potato' , 'quinoa' , 'crackers' ] ;
7
+ let veggies = [ 'peas' , 'green beans' , 'kale' , 'edamame' , 'broccoli' , 'asparagus' ] ;
8
+ let beverages = [ 'juice' , 'milk' , 'water' , 'soy milk' , 'soda' , 'tea' ] ;
9
+ let desserts = [ 'apple' , 'banana' , 'more kale' , 'ice cream' , 'chocolate' , 'kiwi' ] ;
10
10
11
11
12
12
function mealAssembly ( protein , grains , veggies , beverages , desserts , numMeals ) {
@@ -15,6 +15,15 @@ function mealAssembly(protein, grains, veggies, beverages, desserts, numMeals) {
15
15
16
16
/// Part A #2: Write a ``for`` loop inside this function
17
17
/// Code your solution for part A #2 below this comment (and above the return statement) ... ///
18
+
19
+
20
+ for ( let i = 0 ; i < numMeals ; i ++ ) {
21
+ let tempMeal = [ ] ;
22
+ for ( let j = 0 ; j < pantry . length ; j ++ ) {
23
+ tempMeal [ j ] = pantry [ j ] [ i ] ;
24
+ }
25
+ meals . push ( tempMeal ) ;
26
+ }
18
27
19
28
20
29
return meals ;
@@ -23,8 +32,10 @@ function mealAssembly(protein, grains, veggies, beverages, desserts, numMeals) {
23
32
24
33
function askForNumber ( ) {
25
34
numMeals = input . question ( "How many meals would you like to make?" ) ;
26
-
27
35
/// CODE YOUR SOLUTION TO PART B here ///
36
+ while ( numMeals < 1 || numMeals > 6 ) {
37
+ numMeals = input . question ( "Invaild number. Enter 1 - 6." ) ;
38
+ }
28
39
29
40
return numMeals ;
30
41
}
@@ -45,16 +56,16 @@ function runProgram() {
45
56
/// Change the final input variable (aka numMeals) here to ensure your solution makes the right number of meals ///
46
57
/// We've started with the number 2 for now. Does your solution still work if you change this value? ///
47
58
48
- // let meals = mealAssembly(protein, grains, veggies, beverages, desserts, 2);
49
- // console.log(meals)
59
+ //let meals = mealAssembly(protein, grains, veggies, beverages, desserts, 2);
60
+ //console.log(meals)
50
61
51
62
52
63
/// TEST PART B HERE ///
53
64
/// UNCOMMENT the next two lines to test your ``askForNumber`` solution ///
54
65
/// Tip - don't test this part until you're happy with your solution to part A #2 ///
55
66
56
- // let mealsForX = mealAssembly(protein, grains, veggies, beverages, desserts, askForNumber());
57
- // console.log(mealsForX);
67
+ let mealsForX = mealAssembly ( protein , grains , veggies , beverages , desserts , askForNumber ( ) ) ;
68
+ console . log ( mealsForX ) ;
58
69
59
70
/// TEST PART C HERE ///
60
71
/// UNCOMMENT the remaining commented lines and change the password1 and password2 strings to ensure your code is doing its job ///
@@ -75,4 +86,4 @@ module.exports = {
75
86
askForNumber : askForNumber ,
76
87
generatePassword : generatePassword ,
77
88
runProgram : runProgram
78
- } ;
89
+ } ;
0 commit comments