Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
74 lines (59 loc) · 1.76 KB
/
Copy pathscript.js
File metadata and controls
74 lines (59 loc) · 1.76 KB
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
// 1. Create an array named numbers and store 5 number values in it
let numbers = [2, 4, 5, 9, 11];
// 2. Calculates the sum of array items and print it to the console using console.log()
let sum = 0;
for(number of numbers) {
sum += number;
}
console.log(sum);
// 3. Calculates the average of array items and print it to the console using console.log()
let avr = sum / numbers.length;
console.log(avr);
// 4. Find the highest number in the array and print it to the console using console.log()
let highestNumber = numbers[0];
for(number of numbers) {
if (number > highestNumber) {
highestNumber =number;
}
}
console.log(highestNumber);
// 5. Find the lowest number in the array and print it to the console using console.log()
let lowestNumber = numbers[0];
for(number of numbers) {
if (number < lowestNumber) {
lowestNumber =number;
}
}
console.log(lowestNumber);
// 6. Find the even numbers in the array and print them to the console using console.log()
let even = [];
for(let number of numbers){
if(number % 2 === 0){
console.log(number, "even");
}
}
// 7. Find the odd numbers in the array and print them to the console using console.log()
let odd = [];
for(let number of numbers){
if(number % 2 !== 0){
console.log(number, "odd");
}
}
// 8. Find the numbers in the array that is divisible by 5 and print them to the console using console.log()
let divByFive = [];
for(let number of numbers){
if(number % 5 === 0){
console.log(number);
}
}
// 9. Log all the element of the array one by one
for(let number of numbers){
console.log(number);
}
// 10. Find all the number in the array that is divisible by 3
let divBy3 = [];
for(let number of numbers){
if(number % 3 === 0){
console.log(number);
}
}