-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
134 lines (127 loc) · 5.17 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
131
132
133
134
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1 user-scalable=no, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Simple Calculator Ayush Vaishy</title>
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Fjalla+One&display=swap" rel="stylesheet">
<link rel='icon' type='image/x-icon' href='images/favicon.ico' />
</head>
<body>
<div class="container">
<h1>
<div class="toggle-container">
<label class="toggle-switch">
<input type="checkbox" id="toggle-mode" />
<span class="toggle-slider"></span>
</label>
</div>
<a class="tittle" onclick="location.reload();">CALCULATOR</a>
<img id="historybutton" src="images/history.png">
</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 onclick="clearAll()">C</button>
</div>
<div class="col">
<button 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 style="font-size:1rem; display: flex; align-items: center; justify-content: center;">
Made with <img style="margin: 0.15rem;" src="images/heart.png"> by <a style="text-decoration: none; color: #f1c40f; margin-left: 0.25rem;" target="_blank" href="https://github.com/AyushVaishy">Ayush Vaishy</a>
</div>
</div>
</div>
<div id="bar1" class = "bars"></div>
<div id="bar2" class = "bars"></div>
<div id="history"></div>
<div id="turn">
PLEASE TURN YOUR DEVICE
</div>
</body>
<script src="hist.js"></script>
<script src="calc.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<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);
});
// This function will be responsible for handling the button press from the keyboard..Try thses key also if want you can also chnage these settings,...
function handleKeyPress(key) {
// "Enter" key is pressed, trigger the "=" button press
if (key === 'Enter') {
handleButtonPress('=');
}
// "Delete" or "Backspace" key is pressed, trigger the "CE" button press
if (key === 'Delete' || key === 'Backspace') {
handleButtonPress('CE');
}
//number key is pressed, trigger the corresponding number button press
if (/[0-9]/.test(key)) {
handleButtonPress(key);
}
// operator key is pressed (+, -, *, /), trigger the corresponding operator button press
if (/[\+\-\*\/%]/.test(key)) {
handleButtonPress(key);
}
}
function handleButtonPress(value) {
// This function simulates the button press of the calculator for the given value
// Find the corresponding button element based on the value
const button = document.querySelector(`button[value="${value}"]`);
if (button) {
button.click();
}
}
</script>
</html>