Skip to content

Commit f818368

Browse files
studio
1 parent b43e10e commit f818368

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

loops/studio/solution.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ const input = require('readline-sync');
22

33
// Part A: #1 Populate these arrays
44

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'];
1010

1111

1212
function mealAssembly(protein, grains, veggies, beverages, desserts, numMeals) {
@@ -15,6 +15,15 @@ function mealAssembly(protein, grains, veggies, beverages, desserts, numMeals) {
1515

1616
/// Part A #2: Write a ``for`` loop inside this function
1717
/// 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+
}
1827

1928

2029
return meals;
@@ -23,8 +32,10 @@ function mealAssembly(protein, grains, veggies, beverages, desserts, numMeals) {
2332

2433
function askForNumber() {
2534
numMeals = input.question("How many meals would you like to make?");
26-
2735
/// CODE YOUR SOLUTION TO PART B here ///
36+
while (numMeals < 1 || numMeals > 6) {
37+
numMeals = input.question("Invaild number. Enter 1 - 6.");
38+
}
2839

2940
return numMeals;
3041
}
@@ -45,16 +56,16 @@ function runProgram() {
4556
/// Change the final input variable (aka numMeals) here to ensure your solution makes the right number of meals ///
4657
/// We've started with the number 2 for now. Does your solution still work if you change this value? ///
4758

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)
5061

5162

5263
/// TEST PART B HERE ///
5364
/// UNCOMMENT the next two lines to test your ``askForNumber`` solution ///
5465
/// Tip - don't test this part until you're happy with your solution to part A #2 ///
5566

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);
5869

5970
/// TEST PART C HERE ///
6071
/// 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 = {
7586
askForNumber: askForNumber,
7687
generatePassword: generatePassword,
7788
runProgram: runProgram
78-
};
89+
};

0 commit comments

Comments
 (0)