Not able to see variable value

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

did you try using “event.target.value” instead of what you have shown here?

Hi, I did try that but no luck. Is it something wrong with syntax or the way am passing the value?

share a “codepen” link or something, otherwise it’s not possible to say whats really going on in there!! thanks :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.