-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.html
More file actions
122 lines (118 loc) · 3.87 KB
/
Calculator.html
File metadata and controls
122 lines (118 loc) · 3.87 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculator with Styled Buttons</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
.calculator {
max-width: 300px;
margin: 0 auto;
text-align: center;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
}
.input-section {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.numbers {
flex: 2;
}
.operators {
flex: 1;
}
input[type="text"] {
width: 100%;
margin-bottom: 10px;
padding: 10px;
font-size: 18px;
}
.btn {
width: 48px;
height: 48px;
font-size: 20px;
margin: 5px;
border: none;
border-radius: 50%;
background-color: #007bff;
color: #fff;
cursor: pointer;
transition: background-color 0.2s;
}
.btn:hover {
background-color: #0056b3;
}
.btn-clear {
width: 100px;
height: 60px;
font-size: 24px;
margin: 5px;
border: none;
border-radius: 5px;
background-color: #ff0000;
color: #fff;
}
.btn-calculate {
width: 100px;
height: 60px;
font-size: 24px;
margin: 5px;
border: none;
border-radius: 5px;
background-color: #00cc00;
color: #fff;
}
</style>
</head>
<body>
<div class="calculator">
<input type="text" id="display" disabled>
<div class="input-section">
<div class="numbers">
<button class="btn" onclick="appendToDisplay('7')">7</button>
<button class="btn" onclick="appendToDisplay('8')">8</button>
<button class="btn" onclick="appendToDisplay('9')">9</button>
<button class="btn" onclick="appendToDisplay('4')">4</button>
<button class="btn" onclick="appendToDisplay('5')">5</button>
<button class="btn" onclick="appendToDisplay('6')">6</button>
<button class="btn" onclick="appendToDisplay('1')">1</button>
<button class="btn" onclick="appendToDisplay('2')">2</button>
<button class="btn" onclick="appendToDisplay('3')">3</button>
<button class="btn" onclick="appendToDisplay('0')">0</button>
</div>
<div class="operators">
<button class="btn" onclick="appendToDisplay('+')">+</button>
<button class="btn" onclick="appendToDisplay('-')">-</button>
<button class="btn" onclick="appendToDisplay('*')">*</button>
<button class="btn" onclick="appendToDisplay('/')">/</button>
</div>
</div>
<button class="btn btn-clear" onclick="clearDisplay()">C</button>
<button class="btn btn-calculate" onclick="calculateResult()">=</button>
</div>
<script>
function appendToDisplay(value) {
document.getElementById('display').value += value;
}
function clearDisplay() {
document.getElementById('display').value = '';
}
function calculateResult() {
const display = document.getElementById('display');
try {
display.value = eval(display.value);
} catch (error) {
display.value = 'Error';
}
}
</script>
</body>
</html>