forked from Faruq-Hameed/js-basics2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
144 lines (94 loc) · 2.58 KB
/
app.js
File metadata and controls
144 lines (94 loc) · 2.58 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// ///////*****ASSIGNMENT 1********///////////// */
// let output;
// function showNumber(limit) {
// for (let i = 0; i <= limit; i++)
// if (i % 2 === 0) {
// output = i
// console.log(output + ' EVEN')
// }
// else {
// console.log(i + ' ODD')
// output = i
// }
// return output
// }
// showNumber(50) //e.g
// ///////*****ASSIGNMENT 2********///////////// */
// // const colors = ['red',8, 'green', 'yellow', 'red', 6, 'blue', 200, 600];
// let totalTruthy = 0;
// function countTruthy(array){
// for (let element of array) {
// if (0 / element === 0) {
// totalTruthy += 1
// }
// if (0 / element !== 0) continue;
// else totalTruthy += 1
// }
// return totalTruthy
// }
// const colors = ['red',8, 'green', 'yellow', 'red', 6, 'blue', 200, 600, 0, 0];
// console.log(countTruthy(colors)) //eg
// ///////*****ASSIGNMENT 3********///////////// */
// const person = {
// name: 'Faruq',
// age: 27,
// school: 'UI',
// matriculationYear: 2016,
// course: 'Agric-Econs',
// courseYears: 5,
// graduationYear: 2021,
// friend: '',
// }
// function showProperties(object) {
// for (key in object) {
// if (0 / object[key] === 0) continue;
// else if (!object[key]) continue; /* Added this to take care of falsy values */
// console.log('The ' + key + ' is', object[key]);
// }
// }
// showProperties(person) //eg
// ///////*****ASSIGNMENT 4********///////////// */
// let result = 0;
// function sum(limit) {
// for (let i = 1; i <= limit; i++) {
// if (i % 3 === 0 || i % 5 === 0) {
// result += i;
// }
// }
// console.log(result);
// return result;
// }
// sum(10) //eg
// let result = 0;
// function sum(limit) {
// for (let i = 1; i < limit; i++) {
// if (i % 3 === 0 || i % 5 === 0) {
// result += i;
// }
// }
// console.log(result);
// }
// sum(10) //eg
// ///////*****ASSIGNMENT 5********///////////// */
// function showPrimes(n) {
// jumpHere: for (let i = 2; i <= n; i++) {
// for (let j = 2; j < i; j++) {
// if (i % j == 0) {continue jumpHere;} // Label to jump
// }
// console.log(i);// a prime
// }
// }
// showPrimes(10) //eg
// function isPrime(n) {
// for (let i = 2; i < n; i++) {
// if ( n % i == 0) return false;
// }
// return true;
// }
// function showPrimes(n) {
// for (let i = 2; i < n; i++) {
// if (!isPrime(i)) continue;
// console.log(i); // a prime
// }
// }
// showPrimes(10)