Skip to content

Commit b9f4290

Browse files
Adding New Project
1 parent 9c03db7 commit b9f4290

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

Calculator/Calculator.html

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>Tailwind Calculator</title>
7+
<script src="https://cdn.tailwindcss.com"></script>
8+
</head>
9+
<body class="bg-gray-100 flex items-center justify-center h-screen">
10+
11+
<div class="bg-white p-6 rounded-2xl shadow-lg w-80">
12+
<h1 class="text-2xl font-bold text-center mb-4">Calculator</h1>
13+
14+
<input type="text" id="display" class="w-full text-right text-2xl p-3 mb-4 border rounded-md bg-gray-100" disabled>
15+
16+
<div class="grid grid-cols-4 gap-3">
17+
<!-- Row 1 -->
18+
<button class="btn" onclick="clearDisplay()">C</button>
19+
<button class="btn" onclick="deleteLast()">DEL</button>
20+
<button class="btn" onclick="append('%')">%</button>
21+
<button class="btn bg-orange-500 text-white" onclick="append('/')">/</button>
22+
23+
<!-- Row 2 -->
24+
<button class="btn" onclick="append('7')">7</button>
25+
<button class="btn" onclick="append('8')">8</button>
26+
<button class="btn" onclick="append('9')">9</button>
27+
<button class="btn bg-orange-500 text-white" onclick="append('*')">*</button>
28+
29+
<!-- Row 3 -->
30+
<button class="btn" onclick="append('4')">4</button>
31+
<button class="btn" onclick="append('5')">5</button>
32+
<button class="btn" onclick="append('6')">6</button>
33+
<button class="btn bg-orange-500 text-white" onclick="append('-')">-</button>
34+
35+
<!-- Row 4 -->
36+
<button class="btn" onclick="append('1')">1</button>
37+
<button class="btn" onclick="append('2')">2</button>
38+
<button class="btn" onclick="append('3')">3</button>
39+
<button class="btn bg-orange-500 text-white" onclick="append('+')">+</button>
40+
41+
<!-- Row 5 -->
42+
<button class="btn col-span-2" onclick="append('0')">0</button>
43+
<button class="btn" onclick="append('.')">.</button>
44+
<button class="btn bg-green-500 text-white" onclick="calculate()">=</button>
45+
</div>
46+
</div>
47+
48+
<script>
49+
const display = document.getElementById('display');
50+
51+
function append(value) {
52+
display.value += value;
53+
}
54+
55+
function clearDisplay() {
56+
display.value = '';
57+
}
58+
59+
function deleteLast() {
60+
display.value = display.value.slice(0, -1);
61+
}
62+
63+
function calculate() {
64+
try {
65+
display.value = eval(display.value);
66+
} catch (e) {
67+
display.value = 'Error';
68+
}
69+
}
70+
</script>
71+
72+
<style>
73+
.btn {
74+
@apply bg-gray-200 p-4 rounded-md text-xl font-semibold hover:bg-gray-300;
75+
}
76+
</style>
77+
78+
</body>
79+
</html>

0 commit comments

Comments
 (0)