-
Notifications
You must be signed in to change notification settings - Fork 0
/
sum.js
50 lines (41 loc) · 1.16 KB
/
sum.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
var Addition = function() {
var globalSum = 0;
this.add = function() {
var result = 0;
if(arguments.length > 1) {
var i;
for(i = 0; i < arguments.length; i++) {
result += arguments[i];
}
} else if(arguments.length === 1) {
globalSum += arguments[0];
result = globalSum;
} else {
result = globalSum;
}
return result;
}
this.reset = function() {
globalSum = 0;
}
}
function run() {
var adder = new Addition();
console.log("Adding 2 numbers: 2 + 4");
console.log(adder.add(2, 4));
console.log("Adding 5 numbers: 1, 2, 3, 4, 5");
console.log(adder.add(1, 2, 3, 4, 5));
console.log("Adding lonely 1");
console.log(adder.add(1));
console.log("Adding lonely 1");
console.log(adder.add(1));
console.log("Adding lonely 1");
console.log(adder.add(1));
console.log("Adding lonely 1");
console.log(adder.add(1));
console.log("Adding lonely 1");
console.log(adder.add(1));
console.log("Adding lonely 1");
console.log(adder.add(1));
}
console.log('type run()');