forked from MAP-NCU2015/Lesson-04-Testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
29 lines (29 loc) · 996 Bytes
/
main.js
File metadata and controls
29 lines (29 loc) · 996 Bytes
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
window.onload = function(){
document.getElementById('go_btn').onclick = function(){
var num1Str = document.getElementById('num1').value;
var num2Str = document.getElementById('num2').value;
if (!isNumber(num1Str) || !isNumber(num2Str)){
alert("Some of the input is not a number!")
document.getElementById('ans').value = "ERROR"
return
}
var num1 = parseFloat(num1Str)
var num2 = parseFloat(num2Str)
var operator = document.getElementById('operator').value;
if (operator == "add"){
document.getElementById('ans').value = add(num1, num2);
}
else if (operator == "substract"){
document.getElementById('ans').value = substract(num1, num2);
}
else if (operator == "multiplication"){
document.getElementById('ans').value = multiplication(num1, num2);
}
else if (operator == "divide"){
document.getElementById('ans').value = divide(num1, num2);
}
else {
alert("Bad operator!")
}
}
}