-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.html
72 lines (70 loc) · 2.45 KB
/
calc.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
70
71
72
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Calculator</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<style>
.calculator {
margin: 20px auto;
width: 300px;
border: 1px solid #ccc;
border-radius: 5px;
padding: 10px;
}
.calculator button {
width: 50px;
height: 50px;
margin: 5px;
}
</style>
</head>
<body>
<div class="container">
<div class="calculator">
<input type="text" id="result" class="form-control">
<div>
<button class="btn btn-primary" onclick="append('7')">7</button>
<button class="btn btn-primary" onclick="append('8')">8</button>
<button class="btn btn-primary" onclick="append('9')">9</button>
<button class="btn btn-primary" onclick="append('/')">/</button>
</div>
<div>
<button class="btn btn-primary" onclick="append('4')">4</button>
<button class="btn btn-primary" onclick="append('5')">5</button>
<button class="btn btn-primary" onclick="append('6')">6</button>
<button class="btn btn-primary" onclick="append('*')">*</button>
</div>
<div>
<button class="btn btn-primary" onclick="append('1')">1</button>
<button class="btn btn-primary" onclick="append('2')">2</button>
<button class="btn btn-primary" onclick="append('3')">3</button>
<button class="btn btn-primary" onclick="append('-')">-</button>
</div>
<div>
<button class="btn btn-primary" onclick="append('0')">0</button>
<button class="btn btn-primary" onclick="append('.')">.</button>
<button class="btn btn-primary" onclick="calculate()">=</button>
<button class="btn btn-primary" onclick="append('+')">+</button>
</div>
<div>
<button class="btn btn-danger" onclick="clearResult()">C</button>
</div>
</div>
</div>
<script>
function append(value) {
$('#result').val($('#result').val() + value);
}
function calculate() {
$('#result').val(eval($('#result').val()));
}
function clearResult() {
$('#result').val('');
}
</script>
</body>
</html>