-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlgorithm_2.js
More file actions
113 lines (93 loc) · 1.55 KB
/
Algorithm_2.js
File metadata and controls
113 lines (93 loc) · 1.55 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
//PART ONE//
function multiply(x,y){
console.log(x);
console.log(y);
}
b = multiply(2,3);
console.log(b);
//Output = 6
function multiply(x,y){
return x*y;
}
b = multiply(2,3);
console.log(b);
console.log(multiply(5,2));
//Output = 6, 10
var x = [1,2,3,4,5,10];
for(var i=0; i<5; i++)
{
i = i + 3;
console.log(i);
}
//Output = 3,7
x=15;
console.log(x);
function awesome(){
x=10;
console.log(x);
}
console.log(x);
awesome();
console.log(x);
//Output = 15,15,10,10
for(var i=0; i<15; i+=2){
console.log(i);
}
//Output = 0,2,4,6,8,10,12,14
for(var i=0; i<3; i++){
for(var j=0; j<2; j++){
console.log(i*j);
}
}
//Output = 0,0,0,1,0,2
function looping(x,y){
for(var i=0; i<x; i++){
for(var j=0; j<x; j++){
console.log(i*j);
}
}
}
z = looping(3,3);
console.log(z);
//Output = 0,0,0,0,1,2,0,2,4
function looping(x,y){
for(var i=0; i<x; i++){
for(var j=0; j<y; j++){
console.log(i*j);
}
}
return x*y;
}
z = looping(3,5);
console.log(z);
//Output = 0,0,0,0,0,0,1,2,3,4,0,2,4,6,8,15
//PART TWO//
function printUpTo(x){
for(var i=1; i<=x; i++){
console.log(i)
}
if(x<0){
console.log("negative number");
return false;
}
}
printUpTo(1000000);
y = printUpTo(-10);
console.log(y);
function printSum(x){
sum = 0
for(i=0; i<x; i++){
sum += i;
}
return sum;
}
y = printSum(255)
console.log(y)
function printSumArray(x){
sum = 0;
for(var i=0; i<x.length; i++){
sum += x[i];
}
return sum;
}
console.log ( printSumArray ([1,2,3]));