You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/*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
-
7
-
8
-
9
-
10
-
/*Exercise #2:
11
-
Initialize two variables to hold the string “LaunchCode” and the array [1, 5, ‘LC101’, ‘blue’, 42].
12
-
13
-
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. */
17
-
18
-
19
-
20
-
21
-
22
-
/*Exercise #3:Construct a for loop that sorts the array [2, 3, 13, 18, -5, 38, -10, 11, 0, 104] into two new arrays:
23
-
a. One array contains the even numbers, and the other holds the odds.
24
-
b. Print the arrays to confirm the results. */
1
+
// Exercise #1
2
+
// a. Print the numbers 0 - 20, one number per line.
3
+
for(leti=0;i<=20;i++){
4
+
console.log(i);
5
+
}
6
+
7
+
// b. Print only the ODD values from 3 - 29, one number per line.
8
+
for(leti=3;i<=29;i+=2){
9
+
console.log(i);
10
+
}
11
+
12
+
// c. Print the EVEN numbers 12 to -14 in descending order, one number per line.
13
+
for(leti=12;i>=-14;i-=2){
14
+
console.log(i);
15
+
}
16
+
17
+
// d. Challenge - Print the numbers 50 - 20 in descending order, but only if the numbers are multiples of 3.
18
+
for(leti=50;i>=20;i--){
19
+
if(i%3===0){
20
+
console.log(i);
21
+
}
22
+
}
23
+
24
+
// Exercise #2
25
+
letstr="LaunchCode";
26
+
letarr=[1,5,'LC101','blue',42];
27
+
28
+
// a. Print each element of the array to a new line.
29
+
for(leti=0;i<arr.length;i++){
30
+
console.log(arr[i]);
31
+
}
32
+
33
+
// b. Print each character of the string - in reverse order - to a new line.
34
+
for(leti=str.length-1;i>=0;i--){
35
+
console.log(str[i]);
36
+
}
37
+
38
+
// Exercise #3
39
+
letnums=[2,3,13,18,-5,38,-10,11,0,104];
40
+
letevenNums=[];
41
+
letoddNums=[];
42
+
43
+
// a. One array contains the even numbers, and the other holds the odds.
0 commit comments