forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.js
More file actions
85 lines (63 loc) · 2.87 KB
/
solution.js
File metadata and controls
85 lines (63 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const input = require('readline-sync');
// Part A: #1 Populate these arrays
let protein = ['chicken', 'pork', 'tofu', 'beef', 'fish', 'beans'];
let grains = ['rice', 'pasta', 'corn', 'potato', 'quinoa', 'crackers'];
let veggies = ['peas', 'green beans', 'kale', 'edamame', 'broccoli', 'asparagus'];
let beverages = ['juice', 'milk', 'water', 'soy milk', 'soda', 'tea'];
let desserts = ['apple', 'banana', 'more kale', 'ice cream', 'chocolate', 'kiwi'];
function mealAssembly(protein, grains, veggies, beverages, desserts, numMeals) {
let pantry = [protein, grains, veggies, beverages, desserts];
let meals = [];
/// Part A #2: Write a ``for`` loop inside this function
/// Code your solution for part A #2 below this comment (and above the return statement) ... ///
for(let i = 0; i < numMeals.length; i++){
meals[i] = []; // meals[i] == meal [..., i'th iteration ->[ ], ...]
for(let j = 0; j < pantry.length; j++){
meals[i].push(pantry[j][i]);
}
}
return meals;
}
function askForNumber() {
let numMeals = input.question("How many meals would you like to make?");
/// CODE YOUR SOLUTION TO PART B here ///
while (numMeals <= 0 || numMeals > 6) {
numMeals = Number(input.question("How many meals would you like to make? "));
}
return numMeals;
}
function generatePassword(string1, string2) {
let code = '';
/// Code your Bonus Mission Solution here ///
return code;
}
function runProgram() {
/// TEST PART A #2 HERE ///
/// UNCOMMENT the two lines of code below that invoke the mealAssembly function (starting with 'let meals =') and print the result ///
/// Change the final input variable (aka numMeals) here to ensure your solution makes the right number of meals ///
/// We've started with the number 2 for now. Does your solution still work if you change this value? ///
// let meals = mealAssembly(protein, grains, veggies, beverages, desserts, 2);
// console.log(meals)
/// TEST PART B HERE ///
/// UNCOMMENT the next two lines to test your ``askForNumber`` solution ///
/// Tip - don't test this part until you're happy with your solution to part A #2 ///
// let mealsForX = mealAssembly(protein, grains, veggies, beverages, desserts, askForNumber());
// console.log(mealsForX);
/// TEST PART C HERE ///
/// UNCOMMENT the remaining commented lines and change the password1 and password2 strings to ensure your code is doing its job ///
// let password1 = '';
// let password2 = '';
// console.log("Time to run the password generator so we can update the menu tomorrow.")
// console.log(`The new password is: ${generatePassword(password1, password2)}`);
}
module.exports = {
protein: protein,
grains: grains,
veggies: veggies,
beverages: beverages,
desserts: desserts,
mealAssembly: mealAssembly,
askForNumber: askForNumber,
generatePassword: generatePassword,
runProgram: runProgram
};