I'm new to coding and to JavaScript, and I wanted to code a calculator as a task. Everything worked well until now: My question is: Can I use keys to use my calculator? So, e.g. if I want type the number 5 into my calculator, I have to press on the button I created with my mouse. How can I assign keys to them?
You can use the keydown event. For example, the following code should solve your problem. It listens for when the 5 key goes down and has a comment where you should call whatever function you need to use.
document.addEventListener("keydown", e => {
if(e.code == "Digit5"){
// Add the number 5 to your calculator
}
});