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
103 lines (78 loc) · 3.22 KB
/
Copy pathsolution.js
File metadata and controls
103 lines (78 loc) · 3.22 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const { run } = require('jest');
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; i++) {
let meal = [];
for(let j = 0; j <pantry.length; j++) {
meal.push(pantry[j][i]);
}
meals.push(meal)
}
return meals;
}
function askForNumber() {
numMeals = Number(input.question("How many meals would you like to make?"));
/// CODE YOUR SOLUTION TO PART B here ///
while(numMeals < 1 || numMeals > 6 || isNaN(numMeals) || numMeals % 1 !==0){
numMeals = Number(input.question("Input must be between 1-6 and a whole number. Enter again: "))
}
return numMeals;
}
function generatePassword(string1, string2) {
let code = '';
/// Code your Bonus Mission Solution here ///
let password1 = 'pswr';
let password2 = 'asod';
for(let i = 0; i < password1.length; i++) {
if (i < password1.length) {
code += password1[i];
// console.log(`password1 iteration visual: ${code}`)
if (i < password2.length) {
code += password2[i];
// console.log(`password2 iteration visual: ${code}\n`)
}
}
}
//console.log(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, 3);
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 = 'pswr';
let password2 = 'asod';
console.log("Time to run the password generator so we can update the menu tomorrow.")
console.log(`The new password is: ${generatePassword(password1, password2)}`);
}
runProgram()
module.exports = {
protein: protein,
grains: grains,
veggies: veggies,
beverages: beverages,
desserts: desserts,
mealAssembly: mealAssembly,
askForNumber: askForNumber,
generatePassword: generatePassword,
runProgram: runProgram
};