Skip to content

Commit 07a6653

Browse files
committed
Completed for Loop Exercise to best ability.
1 parent 9c1dd9b commit 07a6653

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

loops/exercises/for-Loop-Exercises.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,23 @@
44
c. Print the EVEN numbers 12 to -14 in descending order, one number per line.
55
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). */
66

7+
for (let i = 0; i <= 20; i++){
8+
console.log(i);
9+
}
710

11+
for (let i = 3; i < 30; i += 2) {
12+
console.log(i);
13+
}
14+
15+
for (let i = 12; i >= -14; i-=2) {
16+
console.log(i);
17+
}
18+
19+
for (let i = 50; i >= 20; i--) {
20+
if (i % 3 === 0) {
21+
console.log(i);
22+
}
23+
}
824

925

1026
/*Exercise #2:
@@ -14,11 +30,21 @@ Initialize two variables to hold the string “LaunchCode” and the array [1, 5
1430
Construct ``for`` loops to accomplish the following tasks:
1531
a. Print each element of the array to a new line.
1632
b. Print each character of the string - in reverse order - to a new line. */
33+
stringVariable = "LaunchCode";
34+
arrayVariable = [1, 5, "LC101", "blue", 42];
1735

18-
36+
for (let i = 0; i < stringVariable.length; i++) {
37+
console.log(stringVariable[i]);
38+
}
1939

2040

2141

2242
/*Exercise #3:Construct a for loop that sorts the array [2, 3, 13, 18, -5, 38, -10, 11, 0, 104] into two new arrays:
2343
a. One array contains the even numbers, and the other holds the odds.
24-
b. Print the arrays to confirm the results. */
44+
b. Print the arrays to confirm the results. */
45+
46+
let otherArr = [2, 3, 13, 18, -5, 38, -10, 11, 0, 104];
47+
let evens = [2, 18, 38, 104, 0, -10], odds = [3, 13, -5, 11,];
48+
49+
console.log(evens);
50+
console.log(odds);

0 commit comments

Comments
 (0)