Skip to content

Commit b48c3fe

Browse files
committed
studio update
1 parent b1e6b4d commit b48c3fe

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

loops/studio/solution.js

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,27 @@ 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) {
1313
let pantry = [protein, grains, veggies, beverages, desserts];
1414
let meals = [];
15-
15+
for ( let i = 0; i < numMeals; i++) {
16+
17+
let meal = [];
18+
19+
for (let m = 0; m < pantry.length ; m++){
20+
meal.push(pantry[m][i]);
21+
22+
}
23+
meals.push(meal)
24+
}
25+
1626
/// Part A #2: Write a ``for`` loop inside this function
1727
/// Code your solution for part A #2 below this comment (and above the return statement) ... ///
1828

@@ -23,15 +33,26 @@ function mealAssembly(protein, grains, veggies, beverages, desserts, numMeals) {
2333

2434
function askForNumber() {
2535
numMeals = input.question("How many meals would you like to make?");
26-
2736
/// CODE YOUR SOLUTION TO PART B here ///
37+
while (numMeals < 0 || numMeals > 6)
38+
numMeals = input.question (" Please enter a number between 1 & 6.");
2839

2940
return numMeals;
3041
}
3142

3243

44+
3345
function generatePassword(string1, string2) {
3446
let code = '';
47+
string1 = "12345";
48+
string2 = "67890";
49+
string1.split("");
50+
string2.split("");
51+
let codeArray = []
52+
for ( i = 0; i < string1.length; i++){
53+
codeArray.push(string1[i],string2[i]);
54+
}
55+
code = codeArray.join ("");
3556

3657
/// Code your Bonus Mission Solution here ///
3758

@@ -45,24 +66,24 @@ function runProgram() {
4566
/// Change the final input variable (aka numMeals) here to ensure your solution makes the right number of meals ///
4667
/// We've started with the number 2 for now. Does your solution still work if you change this value? ///
4768

48-
// let meals = mealAssembly(protein, grains, veggies, beverages, desserts, 2);
49-
// console.log(meals)
69+
let meals = mealAssembly(protein, grains, veggies, beverages, desserts, 6);
70+
console.log(meals)
5071

5172

5273
/// TEST PART B HERE ///
5374
/// UNCOMMENT the next two lines to test your ``askForNumber`` solution ///
5475
/// Tip - don't test this part until you're happy with your solution to part A #2 ///
5576

56-
// let mealsForX = mealAssembly(protein, grains, veggies, beverages, desserts, askForNumber());
57-
// console.log(mealsForX);
77+
let mealsForX = mealAssembly(protein, grains, veggies, beverages, desserts, askForNumber());
78+
console.log(mealsForX);
5879

5980
/// TEST PART C HERE ///
6081
/// UNCOMMENT the remaining commented lines and change the password1 and password2 strings to ensure your code is doing its job ///
6182

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)}`);
83+
let password1 = '';
84+
let password2 = '';
85+
console.log("Time to run the password generator so we can update the menu tomorrow.")
86+
console.log(`The new password is: ${generatePassword(password1, password2)}`);
6687
}
6788

6889
module.exports = {

0 commit comments

Comments
 (0)