@@ -2,30 +2,43 @@ 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 ) {
13
13
let pantry = [ protein , grains , veggies , beverages , desserts ] ;
14
14
let meals = [ ] ;
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
+ for ( i = 0 ; i < numMeals ; i ++ ) {
19
+ let individualMeal = [ ] ;
18
20
19
-
21
+ for ( let j = 0 ; j < pantry . length ; j ++ ) {
22
+ individualMeal . push ( pantry [ j ] [ i ] )
23
+ }
24
+ meals . push ( individualMeal )
20
25
return meals ;
21
26
}
22
27
23
28
24
29
function askForNumber ( ) {
25
- numMeals = input . question ( "How many meals would you like to make?" ) ;
26
-
30
+ let numPass = false
31
+
27
32
/// CODE YOUR SOLUTION TO PART B here ///
28
33
34
+ while ( ! numPass ) {
35
+ numMeals = input . question ( "How many meals would you like to make?" ) ;
36
+ if ( numMeals > 6 || numMeals < 1 || isNan ( numMeals ) ) {
37
+ console . log ( "Value out of range. Please try again." )
38
+ } else {
39
+ numPass = true ;
40
+ }
41
+ }
29
42
return numMeals ;
30
43
}
31
44
@@ -35,34 +48,36 @@ function generatePassword(string1, string2) {
35
48
36
49
/// Code your Bonus Mission Solution here ///
37
50
51
+ for ( let i = 0 ; i < string1 . length ; i ++ ) {
52
+ code += string1 [ i ] + string2 [ i ]
38
53
return code ;
39
54
}
40
55
41
56
function runProgram ( ) {
42
-
57
+
43
58
/// TEST PART A #2 HERE ///
44
59
/// UNCOMMENT the two lines of code below that invoke the mealAssembly function (starting with 'let meals =') and print the result ///
45
60
/// Change the final input variable (aka numMeals) here to ensure your solution makes the right number of meals ///
46
61
/// We've started with the number 2 for now. Does your solution still work if you change this value? ///
47
-
48
- // let meals = mealAssembly(protein, grains, veggies, beverages, desserts, 2);
49
- // console.log(meals)
50
-
51
62
63
+ let meals = mealAssembly ( protein , grains , veggies , beverages , desserts , 2 ) ;
64
+ console . log ( meals )
65
+
66
+ }
52
67
/// TEST PART B HERE ///
53
68
/// UNCOMMENT the next two lines to test your ``askForNumber`` solution ///
54
69
/// Tip - don't test this part until you're happy with your solution to part A #2 ///
55
-
56
- // let mealsForX = mealAssembly(protein, grains, veggies, beverages, desserts, askForNumber());
57
- // console.log(mealsForX);
70
+
71
+ let mealsForX = mealAssembly ( protein , grains , veggies , beverages , desserts , askForNumber ( ) ) ;
72
+ console . log ( mealsForX ) ;
58
73
59
74
/// TEST PART C HERE ///
60
75
/// UNCOMMENT the remaining commented lines and change the password1 and password2 strings to ensure your code is doing its job ///
61
76
62
- // let password1 = '';
63
- // let password2 = '';
64
- // console.log("Time to run the password generator so we can update the menu tomorrow.")
65
- // console.log(`The new password is: ${generatePassword(password1, password2)}`);
77
+ let password1 = '6789 ' ;
78
+ let password2 = 'dgef ' ;
79
+ console . log ( "Time to run the password generator so we can update the menu tomorrow." )
80
+ console . log ( `The new password is: ${ generatePassword ( password1 , password2 ) } ` ) ;
66
81
}
67
82
68
83
module . exports = {
@@ -74,5 +89,6 @@ module.exports = {
74
89
mealAssembly : mealAssembly ,
75
90
askForNumber : askForNumber ,
76
91
generatePassword : generatePassword ,
77
- runProgram : runProgram
78
- } ;
92
+ runProgram : runProgram
93
+ }
94
+ }
0 commit comments