Skip to content

Commit 1437ce0

Browse files
committed
Finished loop Studio
1 parent ec171a0 commit 1437ce0

File tree

4,122 files changed

+441082
-32
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,122 files changed

+441082
-32
lines changed

loops/exercises/javascript-projects

Lines changed: 0 additions & 1 deletion
This file was deleted.

loops/exercises/test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*Exercise #1: Construct for loops that accomplish the following tasks:
2+
a. Print the numbers 0 - 20, one number per line.
3+
b. Print only the ODD values from 3 - 29, one number per line.
4+
c. Print the EVEN numbers 12 to -14 in descending order, one number per line.
5+
d. Challenge - Print the numbers 50 - 20 in descending order, but only if the numbers are multiples of 3. (Your code should work even if you replace 50 or 20 with other numbers). */
6+
for (let i = 0; i <= 20; i++) {
7+
console.log(i);
8+
}
9+
10+
11+
12+
/*Exercise #2:
13+
Initialize two variables to hold the string “LaunchCode” and the array [1, 5, ‘LC101’, ‘blue’, 42].
14+
15+
16+
Construct ``for`` loops to accomplish the following tasks:
17+
a. Print each element of the array to a new line.
18+
b. Print each character of the string - in reverse order - to a new line. */
19+
20+
21+
22+
23+
24+
/*Exercise #3:Construct a for loop that sorts the array [2, 3, 13, 18, -5, 38, -10, 11, 0, 104] into two new arrays:
25+
a. One array contains the even numbers, and the other holds the odds.
26+
b. Print the arrays to confirm the results. */

loops/studio/solution.js

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,39 @@ 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 = [];
1515

16+
1617
/// Part A #2: Write a ``for`` loop inside this function
1718
/// Code your solution for part A #2 below this comment (and above the return statement) ... ///
18-
19+
for (let item = 0; item < numMeals; item++) {
20+
let meal = [];
21+
for (let variety = 0; variety < pantry.length; variety++) {
22+
meal.push(pantry[variety][item])
23+
}
24+
meals.push(meal);
25+
}
1926

2027
return meals;
2128
}
2229

2330

2431
function askForNumber() {
25-
numMeals = input.question("How many meals would you like to make?");
26-
27-
/// CODE YOUR SOLUTION TO PART B here ///
32+
numMeals = input.question("How many meals would you like to make? ");
33+
/// CODE YOUR SOLUTION TO PART B here ///
34+
while (numMeals < 1 || numMeals > 6 || isNaN(numMeals)) {
35+
numMeals = input.question("How many meals would you like to make? ");
36+
}
37+
2838

2939
return numMeals;
3040
}
@@ -33,7 +43,15 @@ function askForNumber() {
3343
function generatePassword(string1, string2) {
3444
let code = '';
3545

36-
/// Code your Bonus Mission Solution here ///
46+
/// Code your Bonus Mission Solution here ///
47+
for (let i = 0; i < string1.length || i < string2.length; i++) {
48+
if (i < string1.length) {
49+
code += string1[i];
50+
}
51+
if (i < string2.length) {
52+
code += string2[i];
53+
}
54+
}
3755

3856
return code;
3957
}
@@ -53,16 +71,16 @@ function runProgram() {
5371
/// UNCOMMENT the next two lines to test your ``askForNumber`` solution ///
5472
/// Tip - don't test this part until you're happy with your solution to part A #2 ///
5573

56-
// let mealsForX = mealAssembly(protein, grains, veggies, beverages, desserts, askForNumber());
57-
// console.log(mealsForX);
74+
let mealsForX = mealAssembly(protein, grains, veggies, beverages, desserts, askForNumber());
75+
console.log(mealsForX);
5876

5977
/// TEST PART C HERE ///
6078
/// UNCOMMENT the remaining commented lines and change the password1 and password2 strings to ensure your code is doing its job ///
6179

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)}`);
80+
let password1 = 'ABCD';
81+
let password2 = '1234';
82+
console.log("Time to run the password generator so we can update the menu tomorrow.")
83+
console.log(`The new password is: ${generatePassword(password1, password2)}`);
6684
}
6785

6886
module.exports = {

unit-testing/chapter-examples/hello-jest/node_modules/.bin/browserslist

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

unit-testing/chapter-examples/hello-jest/node_modules/.bin/browserslist.cmd

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

unit-testing/chapter-examples/hello-jest/node_modules/.bin/browserslist.ps1

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

unit-testing/chapter-examples/hello-jest/node_modules/.bin/create-jest

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

unit-testing/chapter-examples/hello-jest/node_modules/.bin/create-jest.cmd

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

unit-testing/chapter-examples/hello-jest/node_modules/.bin/create-jest.ps1

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

unit-testing/chapter-examples/hello-jest/node_modules/.bin/esparse

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

unit-testing/chapter-examples/hello-jest/node_modules/.bin/esparse.cmd

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

unit-testing/chapter-examples/hello-jest/node_modules/.bin/esparse.ps1

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

unit-testing/chapter-examples/hello-jest/node_modules/.bin/esvalidate

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

unit-testing/chapter-examples/hello-jest/node_modules/.bin/esvalidate.cmd

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

unit-testing/chapter-examples/hello-jest/node_modules/.bin/esvalidate.ps1

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

unit-testing/chapter-examples/hello-jest/node_modules/.bin/import-local-fixture

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

unit-testing/chapter-examples/hello-jest/node_modules/.bin/import-local-fixture.cmd

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

0 commit comments

Comments
 (0)