-
Notifications
You must be signed in to change notification settings - Fork 0
/
calclator.html
103 lines (94 loc) · 2.63 KB
/
calclator.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
<link rel="stylesheet" type="text/css" href="style.css">
<style>
.calculator {
width: 300px;
margin: 0 auto;
padding: 20px;
background-color: #f2f2f2;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
.display {
margin-bottom: 10px;
}
.display input {
width: 100%;
height: 50px;
font-size: 24px;
text-align: right;
padding: 10px;
border: none;
border-radius: 5px;
box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
}
.buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 10px;
}
button {
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
padding: 10px;
font-size: 24px;
cursor: pointer;
transition: background-color 0.2s ease-in-out;
}
button:hover {
background-color: #3e8e41;
}
</style>
</head>
<body>
<div class="calculator">
<div class="display">
<input type="text" id="result" disabled>
</div>
<div class="buttons">
<button onclick="clearResult()">C</button>
<button onclick="backspace()">←</button>
<button onclick="insertValue('/')">÷</button>
<button onclick="insertValue('*')">x</button>
<button onclick="insertValue('7')">7</button>
<button onclick="insertValue('8')">8</button>
<button onclick="insertValue('9')">9</button>
<button onclick="insertValue('-')">-</button>
<button onclick="insertValue('4')">4</button>
<button onclick="insertValue('5')">5</button>
<button onclick="insertValue('6')">6</button>
<button onclick="insertValue('+')">+</button>
<button onclick="insertValue('1')">1</button>
<button onclick="insertValue('2')">2</button>
<button onclick="insertValue('3')">3</button>
<button onclick="calculate()">=</button>
<button onclick="insertValue('0')">0</button>
<button onclick="insertValue('.')">.</button>
</div>
</div>
<script>
let result = document.getElementById('result');
function insertValue(value) {
result.value += value;
}
function clearResult() {
result.value = '';
}
function backspace() {
result.value = result.value.slice(0, -1);
}
function calculate() {
try {
result.value = eval(result.value);
} catch (error) {
result.value = 'Error';
}
}
</script>
</body>
</html>