Skip to content

Commit 8ec776a

Browse files
committed
feat(JS): create handleKeyPress()
1 parent b6c95cd commit 8ec776a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ const clearHistoryBtn = document.querySelector(".clear-history-btn");
1010
clearHistoryBtn.addEventListener("click", () => {historyElement.innerHTML = "";
1111
});
1212

13+
document.addEventListener('keydown', handleKeyPress);
14+
15+
function handleKeyPress(event) {
16+
const key = event.key;
17+
const button = document.querySelector(`[data-value="${key}"]`);
18+
19+
if (button) {
20+
button.click(); // Trigger the click event for the corresponding button
21+
}
22+
}
23+
24+
1325
const operatorRegex = /[\/*\-+]/;
1426
const ZERO = 0;
1527
const ZERO_DOT = "0.";

0 commit comments

Comments
 (0)