I want to update the variable value when a user clicks on any button and take that value and add it to the declared variable.
Basically am trying to access the variable value outside the function but I do not know if this is the correct way to do it as I can not see any value on my console.
Please let me know if any thoughts on this.
The code.
const operatorKeys = document.querySelectorAll(".operator-keys");
const numKeys = document.querySelectorAll(".num-keys");
let numbers = "";
let operators = "x";
operatorKeys.forEach((el) => {
el.addEventListener("click", (e) => {
operators = e.currentTarget.textContent;
});
});
numKeys.forEach((el) => {
el.addEventListener("click", (e) => {
numbers = e.currentTarget.textContent;
});
});
console.log(`this are ops ${operators}`);
console.log(`this are numbers ${numbers}`);
Thanks for the help and support