1 year ago

#379003

test-img

medOnline5

How do you reset an event?

I'm building a calculator. I can't get it to display the 2nd number that the user wants to calculate. For example, if the user wants to calculate 10 * 2. I want to display the 10. After they click *, I want to store 10 for later use, and display the 2.

//select screen display element
let screen = document.querySelector(".screen");

//select all calculator number keys
let numberKeys = document.querySelectorAll(".keys");

//select operator elements
let operators = document.querySelectorAll(".operators");


numberKeys.forEach((key) => {
  key.addEventListener("click", (e) => {
    screen.innerText += e.target.innerText;
  });
});

operators.forEach((op) => {
  op.addEventListener("click", (e) => {
    screenValue += screen.innerText;
    operator = e.target.innerText;
    secondNumber += screen.innerText;
  });
});

javascript

event-handling

0 Answers

Your Answer

Accepted video resources