Skip to content

Commit

Permalink
Add keyboard support
Browse files Browse the repository at this point in the history
  • Loading branch information
AngeloThys committed Aug 28, 2023
1 parent 9c90ebd commit 2721321
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,46 @@ function assignEventListeners() {
});
}

assignEventListeners();
assignEventListeners();

function addKeyboardSupport() {
document.addEventListener('keyup', (event) => {
if (['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'].includes(event.key)) {
writeNumberToDisplay(event.key);
disablePointButton();
} else if (['*', '/', '-', '+'].includes(event.key)) {
if (operatorOne === null) {
assignOperand();
assignOperator(event.key);
highlightOperator();
} else {
assignOperand();
performOperation();
clearMemory();
assignOperand();
assignOperator(event.key);
highlightOperator();
disablePointButton();
}
} else if (event.key === "Escape") {
clearDisplay();
clearMemory();
highlightOperator();
disablePointButton();
} else if (event.key === "Alt") {
changeSign();
} else if (event.key === "=") {
assignOperand()
performOperation();
clearMemory();
highlightOperator();
disablePointButton();
} else if (event.key === ".") {
writePointToDisplay();
disablePointButton();
}

});
}

addKeyboardSupport();

0 comments on commit 2721321

Please sign in to comment.