-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionlooping.js
More file actions
78 lines (58 loc) · 1.28 KB
/
functionlooping.js
File metadata and controls
78 lines (58 loc) · 1.28 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
/1. print the numbers from 1 to 100 with the interval of 10//
for (let a=10;a<=100;a=a+10)
{
console.log(a);
}
//2. print the number from 10 to 1//
for (let a=10;a>=1;a--)
{
console.log(a);
}
//3. print the multiple of 2 until 10//
for(var i=1;i<=5;i++)
{
console.log(i*2);
}
//4. print the number from 100 to 1 with the difference of 10.//
let num,a;
a=1;
for( num=100;num>=0;num=num-10)
{
if(num==0)
{
console.log(a);
}
else
{
console.log(num);
}
}
/*5. write a function to print the eligble, Not eligble voters separately from the list
of array [18,17,16,15,10,8,7,9,35,40,86,75,0]. Note: print invalid if the voter age is 0.*/
var invalid=[];
var eligible=[];
var Noteligible=[];
function voterlist(age)
{
for (var i=0;i<=age.length-1;i++)
{
if(age[i]>=18 && age[i]>0)
{
eligible.push(age[i]);
}
else
if(age[i]==0)
{
invalid.push(age[i]);
}
else{
Noteligible.push(age[i]);
}
}
return {
Invalidvoters:invalid,
NotEligiblevoters:Noteligible,
Eligiblevoters:eligible
}
}
console.log(voterlist([18,17,16,15,10,8,7,9,35,40,86,75,0]));