Skip to content

Commit f81408a

Browse files
committed
Updated
1 parent 2eb788f commit f81408a

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

loops/Notes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let phrase = "Chili Cook-off";
2+
3+
for (let i = 0; i < phrase.length - 1; i = i + 3) {
4+
console.log(phrase[i]);
5+
}

loops/exercises/for-Loop-Exercises.js

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,56 @@
11
/*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). */
2+
a. Print the numbers 0 - 20, one number per line. */
63

4+
for (let i = 0; i < 21; i++) {
5+
console.log(i);
6+
}
77

8+
// b. Print only the ODD values from 3 - 29, one number per line.//
9+
for (let i = 3; i < 30; i = i + 2) {
10+
console.log(i);
11+
}
12+
13+
// c. Print the EVEN numbers 12 to -14 in descending order, one number per line. //
14+
for (let i = 12; i > -15; i = i - 2) {
15+
console.log(i);
16+
}
17+
// 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). //
18+
for (let i = 50; i > 19; i = i / 3) {
19+
console.log(i);
20+
}
821

922

1023
/*Exercise #2:
11-
Initialize two variables to hold the string “LaunchCode” and the array [1, 5, ‘LC101’, ‘blue’, 42].
24+
Initialize two variables to hold the string “LaunchCode” and the array [1, 5, ‘LC101’, ‘blue’, 42]. */
25+
26+
let course = "LaunchCode";
27+
let courseArray = [1, 5, 'LC101', 'blue', 42];
28+
29+
/*Construct ``for`` loops to accomplish the following tasks:
30+
a. Print each element of the array to a new line. */
1231

32+
for (let i = 0; i < courseArray.length; i++) {
33+
console.log(courseArray[i]);
34+
}
1335

14-
Construct ``for`` loops to accomplish the following tasks:
15-
a. Print each element of the array to a new line.
16-
b. Print each character of the string - in reverse order - to a new line. */
36+
/*b. Print each character of the string - in reverse order - to a new line. */
1737

38+
for (let i = 0; i < courseArray.length; i++) {
39+
console.log(courseArray[i]);
40+
}
1841

1942

2043

2144

2245
/*Exercise #3:Construct a for loop that sorts the array [2, 3, 13, 18, -5, 38, -10, 11, 0, 104] into two new arrays:
2346
a. One array contains the even numbers, and the other holds the odds.
24-
b. Print the arrays to confirm the results. */
47+
b. Print the arrays to confirm the results. */
48+
49+
let numArray = [2, 3, 13, 18, -5, 38, -10, 11, 0, 104];
50+
let evens = [2, 18, 38, -10, 0, 104], odds = [3, 13, -5, 11];
51+
52+
for (let i = 0; i < numArray.length; i++) {
53+
console.log(evens);
54+
console.log(odds);
55+
}
56+

0 commit comments

Comments
 (0)