Skip to content

Commit c4d67df

Browse files
committed
Chapter 9 Studio
1 parent a0ba33f commit c4d67df

File tree

4 files changed

+63
-29
lines changed

4 files changed

+63
-29
lines changed

booleans-and-conditionals/exercises/part-3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let commandOverride = true
3535

3636
/* 6) b) Code the following if/else check:
3737
If fuelLevel is above 20000 AND engineIndicatorLight is NOT red blinking OR commandOverride is true print "Cleared to launch!" Else print "Launch scrubbed!" */
38-
if (fuelLevel > 20000 && engineIndicatorLight != "red blinking" || commandOverride == true){
38+
if (fuelLevel > 20000 && engineIndicatorLight !== "red blinking" || commandOverride == true){
3939
console.log("Cleared to launch!");
4040
}
4141
else {

loops/studio/package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

loops/studio/package.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22
"name": "loops",
33
"version": "1.0.0",
44
"description": "",
5-
"main": "solution.js",
6-
"scripts": {
7-
"test": "jest"
8-
},
5+
"main": "while-Loop-Exercises.js",
96
"author": "",
107
"license": "ISC",
118
"dependencies": {
129
"readline-sync": "^1.4.10"
13-
},
14-
"devDependencies": {
15-
"jest": "^29.7.0"
1610
}
1711
}

loops/studio/solution.js

Lines changed: 37 additions & 21 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,26 +15,41 @@ 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+
for (i = 0; i < numMeals; i++) {
19+
let individualMeal = [];
1820

19-
21+
for(let j = 0; j < pantry.length; j++) {
22+
individualMeal.push(pantry[j][i])
23+
}
24+
meals.push(individualMeal)
2025
return meals;
2126
}
2227

2328

2429
function askForNumber() {
25-
numMeals = input.question("How many meals would you like to make?");
26-
27-
/// CODE YOUR SOLUTION TO PART B here ///
30+
let numPass = false
2831

32+
/// CODE YOUR SOLUTION TO PART B here ///
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+
}
2942
return numMeals;
3043
}
3144

3245

3346
function generatePassword(string1, string2) {
3447
let code = '';
35-
48+
3649
/// Code your Bonus Mission Solution here ///
3750

51+
for (let i = 0; i<string1.length; i++) {
52+
code += string1[i] + string2[i]
3853
return code;
3954
}
4055

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

48-
// let meals = mealAssembly(protein, grains, veggies, beverages, desserts, 2);
49-
// console.log(meals)
63+
let meals = mealAssembly(protein, grains, veggies, beverages, desserts, 2);
64+
console.log(meals)
5065

51-
66+
}
5267
/// TEST PART B HERE ///
5368
/// UNCOMMENT the next two lines to test your ``askForNumber`` solution ///
5469
/// Tip - don't test this part until you're happy with your solution to part A #2 ///
5570

56-
// let mealsForX = mealAssembly(protein, grains, veggies, beverages, desserts, askForNumber());
57-
// console.log(mealsForX);
71+
let mealsForX = mealAssembly(protein, grains, veggies, beverages, desserts, askForNumber());
72+
console.log(mealsForX);
5873

5974
/// TEST PART C HERE ///
6075
/// UNCOMMENT the remaining commented lines and change the password1 and password2 strings to ensure your code is doing its job ///
6176

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)}`);
6681
}
6782

6883
module.exports = {
@@ -74,5 +89,6 @@ module.exports = {
7489
mealAssembly: mealAssembly,
7590
askForNumber: askForNumber,
7691
generatePassword: generatePassword,
77-
runProgram: runProgram
78-
};
92+
runProgram: runProgram
93+
}
94+
}

0 commit comments

Comments
 (0)