-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
130 lines (113 loc) · 4.37 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>CalcHub by Shivam</title>
<link rel="stylesheet" href="./styles/style.css">
<link href="https://fonts.googleapis.com/css?family=Fjalla+One&display=swap" rel="stylesheet">
<meta name="keywords" content="Calculator, Shivam, JavaScript, HTML Calculator, JavaScript Calculator, CalcHub, myselfshivams">
</head>
<body>
<div class="toggle-container">
<label class="toggle-switch">
<input type="checkbox" id="toggle-mode" />
<span class="toggle-slider"></span>
</label>
</div>
<div class="container">
<h1>
<a style="text-decoration: none; color: #c797ef; margin-left: 1.25rem; cursor: pointer;" onclick="location.reload();">CalcHub-CALCULATOR</a>
</h1>
<div class="calculator">
<input type="text" name="screen" id="answer" readonly>
<table>
<tr>
<td><button>(</button></td>
<td><button>)</button></td>
<td>
<div class="row">
<div class="col">
<button style="background-color: #f01600; font-weight: bold; color: #54c8e8; width: 8vw;" onclick="clearAll()">C</button>
</div>
<div class="col">
<button style="background-color: #f01600; font-weight: bold; color: #54c8e8;width: 8vw;" onclick="deleteLastEntry()">CE</button>
</div>
</div>
</td>
<td><button>%</button></td>
</tr>
<tr>
<td><button>7</button></td>
<td><button>8</button></td>
<td><button>9</button></td>
<td><button>X</button></td>
</tr>
<tr>
<td><button>4</button></td>
<td><button>5</button></td>
<td><button>6</button></td>
<td><button>-</button></td>
</tr>
<tr>
<td><button>1</button></td>
<td><button>2</button></td>
<td><button>3</button></td>
<td><button>+</button></td>
</tr>
<tr>
<td><button>0</button></td>
<td><button style="font-weight: bold;">.</button></td>
<td><button>/</button></td>
<td><button style="background-color: #25db72; font-weight: bold; color: #ecf0f1;">=</button></td>
</tr>
</table>
<hr style="max-width: 50vw;">
</div>
</div>
<div id="bar1" class="bars"></div>
<div id="bar2" class="bars"></div>
<div id="turn">
PLEASE RE-SIZE THE WINDOW
</div>
</body>
<script src="./scripts/script.js"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-70447982-5"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'UA-70447982-5');
</script>
<script>
const toggleMode = document.getElementById('toggle-mode');
const container = document.querySelector('.container');
toggleMode.addEventListener('change', function () {
container.classList.toggle('dark-mode');
});
document.addEventListener('keydown', function (event) {
handleKeyPress(event.key);
});
function handleKeyPress(key) {
if (key === 'Enter') {
handleButtonPress('=');
}
if (key === 'Delete' || key === 'Backspace') {
handleButtonPress('CE');
}
if (/[0-9]/.test(key)) {
handleButtonPress(key);
}
if (/[\+\-\*\/%]/.test(key)) {
handleButtonPress(key);
}
}
function handleButtonPress(value) {
const button = document.querySelector(`button[value="${value}"]`);
if (button) {
button.click();
}
}
</script>
</html>