-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
69 lines (68 loc) · 1.96 KB
/
index.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!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>Arithemetic operation </title>
<script src="jquery.js"></script>
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<h1>Arithemetics in Javascript</h1>
<div id="tbl">
<div class="screen">
<label for="input">Result:</label>
<input type="text" class="inpt" id="result" readonly="true">
</div>
<section>
<div>
<label>First number:</label>
<input type="text" id="num1" class="inpt" onkeyup="getresult()">
<div>
<div>
<label>Second number:</label>
<input type="text" id="num2" class="inpt" onkeyup="getresult()">
</div>
<div>
<label for="select">Operator:</label>
<select id="operator" class="inpt">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
</div>
</section>
<p>Powered by Code RIO</p>
</div>
</body>
<script>
$(document).ready(function(){
//This section calls the Dosomething Function
//------------------------------------------
$("#operator").change(function(){
getresult();
});
});
function getresult(){
let num1 = $("#num1").val().trim();
let num2 = $("#num2").val().trim();
let operator = $("#operator").val().trim();
if(num1!='' && num2!=''){
if(operator=='+')
result = parseInt(num1) + parseInt(num2);
else if(operator=='-')
result = parseInt(num1) - parseInt(num2);
else if(operator=='*')
result = parseInt(num1) * parseInt(num2);
else
result = parseInt(num1) / parseInt(num2);
result = result.toFixed(2)
$("#result").val(result);
}else{
$("#result").val('');
}
}
</script>
</html>