I'm building a calculator in HTML, CSS & Javascript. When a user clicks a number it is added to an Array. Which Array it is added to is determined by three variables which are initially set to false. If the variable is true then that Array has already been used.
The problem I am facing is that my event listener for the operands is failing to change the value of the three variables to true when required to do so.
Initial Variables
var numberArrayOne = [];
var numberArrayTwo = [];
var numberArrayThree = [];
var operandOne = false;
var operandTwo = false;
var operandThree = false;
This is the code that listens for operand clicks.
const operandDivide = document.querySelector('.btnDivide');
operandDivide.addEventListener('click', () => {
switch(false){
case (operandOne):
var operandOne = true;
break;
case (operandTwo):
var operandTwo = true;
break;
case (operandThree):
var operandThree = true;
break;
default:
console.log("Error");
}
});
This code chooses which array to place a number into.
const displayFunction = (num) => {
switch(true){
case (!operandOne):
numberArrayOne.push(num);
console.log(numberArrayOne);
break;
case (!operandTwo):
numberArrayTwo.push(num);
console.log(numberArrayTwo);
break;
case (!operandThree):
numberArrayThree.push(num);
break;
default:
}
};
Clicking divide button on my calc the value remains false, it should change to true, and I am getting the console.log(error) message I added as the default.