-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabs.js
78 lines (69 loc) · 1.53 KB
/
labs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// 1
function countdown() {
for (let i = 10; i >= 0; i--) {
if (i === 0){
return "BLAST OFFF"
}
}
}
console.log(countdown())
// 2
function evenNumbers(){
for (let i = 0; i<= 100; i++){
if (i % 2 === 0){
console.log(i);
}
}
}
evenNumbers();
//3
const arrayNum = [1,2,3,4,5,6,7,8,9,10];
let sum = 0;
function sumArray(arrayNum){
for (i = 0; i < arrayNum.length; i++){
sum = sum + arrayNum[i];
}
return sum;
}
console.log('Total sum array = ' + sumArray(arrayNum))
// const arr = [14, 4, 11, 13, 66, 10];
// let sum = 0
// for(const value of arr) {
// sum += value; // sum = sum + value
// }
// console.log(`the sum is ${sum}`);
// LAB 1 - Loops
// Create an array of names of your classmates
// Create a for loop that goes through the array and logs each name in the array
// Now create another for loop that goes through the array in REVERSE and logs each name
// EXAMPLE
// Array: const names = ['Jimmy', 'Frank', 'Ben']
// Output should be:
// Jimmy
// Frank
// Ben
// Ben
// Frank
// Jimmy
const arrayNames = ['Jimmy', 'Frank', 'Ben'];
for (let i = 0; i < arrayNames.length; i++) {
console.log(arrayNames[i]);
}
for (let i = arrayNames.length - 1; i >= 0; i--) {
console.log(arrayNames[i]);
}
// use a for loop to print a half pyramid of *
// Example output:
// *
// **
// ***
// ****
// *****
let pyramid = [];
for(i = 0; i < 5; i++ ){
for(j = i; j <= i; j++){
pyramid.push('*')
}
console.log(...pyramid)
}
//console.log(pyramid)