- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
function Calculation(a, b, op){
if (typeof a == "number" && typeof (b) == "number"){
var result;
+a; +b;
if (op == "+") { result = a+b; alert(result);
} else if (op == "-") { result = a-b; alert(result);
} else if (op == "*"){ result = a*b; alert(result);
} else if (op == "/"){
if (b!=0){
result = a/b; alert(result);
} else {
alert("Can`t divide on zero!");
}
}
} else if (a instanceof Array && b instanceof Array) {
var result = [];
if ( a.length >= b.length ){
length = a.length;
for (var i=0; i < length; i++){
a[i] = parseFloat(a[i]);
b[i] = parseFloat(b[i]);
if (i < b.length-1){
if (op == "+"){ result[i] = a[i]+b[i];
} else if (op == "-"){ result[i] = a[i]-b[i];
} else if (op == "*"){ result[i] = a[i]*b[i];
} else if (op == "/"){
if (b[i]!=0){
result[i] = a[i]/b[i];
} else {
alert("Can`t divide on zero!");
}
}
} else {
result[i] = a[i];
}
}
alert(result.join(" | "));
} else {
length = b.length;
for (var i=0; i < length; i++){
+a[i]; +b[i];
if (i < a.length-1){
switch (op){
case "+":
result[i] = a[i]+b[i];
break;
case "-":
result[i] = a[i]+b[i];
break;
case "*":
result[i] = a[i]+b[i];
break;
case "/":
if (b[i]!=0){
result[i] = a[i]/b[i];
} else {
alert("Can`t divide on zero!");
}
break;
}
} else {
result[i] = a[i];
}
}
alert(result.join(" | "));
}
} else if (a instanceof Object && b instanceof Object) {
var tempObject = {};
switch (op){
case "+":
tempObject.resultA = a.a+b.a;
tempObject.resultB = a.b+b.b;
break;
case "-":
tempObject.resultA = a.a+b.a;
tempObject.resultB = a.b+b.b;
break;
case "*":
tempObject.resultA = a.a+b.a;
tempObject.resultB = a.b+b.b;
break;
case "/":
if (b.b !=0 || b.a != 0){
tempObject.resultA = a.a+b.a;
tempObject.resultB = a.b+b.b;
} else {
alert("Can`t divide on zero!");
}
break;
}
alert(tempObject.resultA + " " + tempObject.resultB);
}
}