-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
105 lines (103 loc) · 2.87 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Colorful Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f0f0f0;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
#calculator {
width: 300px;
padding: 20px;
border-radius: 10px;
background-color: #333;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
color: white;
}
input[type="text"] {
width: 100%;
padding: 10px;
margin-bottom: 10px;
font-size: 18px;
background-color: #444;
border: none;
color: white;
border-radius: 5px;
}
button {
width: 60px;
height: 40px;
font-size: 16px;
margin: 5px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.row {
display: flex;
justify-content: space-between;
}
.number {
background-color: #555;
}
.operator {
background-color: #f39c12;
}
.equal {
background-color: #3498db;
}
</style>
</head>
<body>
<div id="calculator">
<input type="text" id="result" disabled>
<div class="row">
<button class="number" onclick="appendToResult('7')">7</button>
<button class="number" onclick="appendToResult('8')">8</button>
<button class="number" onclick="appendToResult('9')">9</button>
<button class="operator" onclick="appendToResult('/')">/</button>
</div>
<div class="row">
<button class="number" onclick="appendToResult('4')">4</button>
<button class="number" onclick="appendToResult('5')">5</button>
<button class="number" onclick="appendToResult('6')">6</button>
<button class="operator" onclick="appendToResult('*')">*</button>
</div>
<div class="row">
<button class="number" onclick="appendToResult('1')">1</button>
<button class="number" onclick="appendToResult('2')">2</button>
<button class="number" onclick="appendToResult('3')">3</button>
<button class="operator" onclick="appendToResult('-')">-</button>
</div>
<div class="row">
<button class="number" onclick="appendToResult('0')">0</button>
<button class="number" onclick="appendToResult('.')">.</button>
<button class="equal" onclick="calculate()">=</button>
<button class="operator" onclick="appendToResult('+')">+</button>
</div>
</div>
<script>
function appendToResult(value) {
document.getElementById('result').value += value;
}
function calculate() {
try {
const expression = document.getElementById('result').value;
const result = eval(expression);
document.getElementById('result').value = result;
} catch (error) {
document.getElementById('result').value = 'Error';
}
}
</script>
</body>
</html>