-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator_using_js.html
48 lines (43 loc) · 1.26 KB
/
calculator_using_js.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>calculator </title>
</head>
<body>
<input type="number" name="first" id="first" step="any "/>
<select id="opr">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="number" name="second" id="second" step="any"/>
<br>
<button onclick="cal()">calcuated value</button>
<br>
<input type="text" name="" id="result" readonly=""/>
</body>
<script type="text/javascript" >
function cal(){
var opr1=document.getElementById('first').value;
var opr2=document.getElementById('second').value;
var opr=document.getElementById('opr').value;
if(opr=='+'){
var result=parseInt(opr1)+parseInt(opr2);
}
if(opr=='-'){
var result=parseInt(opr1)-parseInt(opr2);
}
if(opr=='*'){
var result=parseInt(opr1)*parseInt(opr2);
}
if(opr=="/"){
var result=parseInt(opr1)/parseInt(opr2);
}
document.getElementById('result').value=result ;
}
</script>
</html>