-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
108 lines (100 loc) · 1.55 KB
/
script.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
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
/* without function
var a = 10;
var b = 20;
var c = a+b;
console.log(c);
*/
/*
with function but no return
function add(a,b){
console.log(a+b);
}
function sub(a,b){
console.log(a-b);
}
add(10,20)
sub(20,10)
*/
/*
function arithmetic(a,b){
console.log(a+b);
console.log(a-b);
console.log(a*b);
console.log(a%b);
}
arithmetic(60,20)
*/
/*
//Normal Function:-
// Print even numbersin an array[1,2,3,4,5,6,7,8,9,10]
var result =[];
function even(arr){
for(var i=0;i<=arr.length-1;i=i+1)
{
if(arr[i]%2===0){
result.push(arr[i])
}
}
return result
}
console.log(even([1,2,3,4,5,6,7,8,9,10]))
*/
/*
//Annonyomus Function
var result =[];
var a = function (arr){
for(var i=0;i<=arr.length-1;i=i+1)
{
if(arr[i]%2===0){
result.push(arr[i])
}
}
return result
}
console.log(a([1,2,3,4,5,6,7,8,9,10]))
*/
/*
//IIFE Function
var result = [];
(function (arr){
for(var i=0;i<=arr.length-1;i=i+1)
{
if(arr[i]%2===0)
{
result.push(arr[i])
}
}
console.log(result);
})([1,2,3,4,5,6,7,8,9,10])
*/
/*
//Arrow Function
var result =[];
var even = (arr) =>{
for(var i=0;i<=arr.length-1;i=i+1)
{
if(arr[i]%2===0)
{
result.push(arr[i])
}
}
return result
}
console.log(even([1,2,3,4,5,6,7,8,9,10]))
*/
/*
//Do While loop
let a = 0;
do{
a += 1;
console.log(a);
}
while(a<5)
*/
// while loop
let a = 0;
let b = 0;
while (a<3){
a++;
b += a;
}