mardi 11 février 2020

Is my if statement ignoring my conditions?

I'm working on a calculator app and I have given each button a value corresponding to their numbers or characters.

I have an if condition that's supposed to check if the user clicks any button other than "C" or "del" (delete) button. If they do click the "C" or "del" button, no value is added to neither the userInput nor the display.

The problem I'm having is that even when I click "C" and "del", the if statement would still execute.

let userInput = '';
const display = document.querySelector('.display');
const buttons = document.querySelectorAll('input[type="button"]');


for (let button of buttons) {

    const value = button.value;

    if (value !== "C" || value !== "del"){
        button.addEventListener("click", function(){
            userInput+=value;
            display.innerHTML += value;
            console.log(button.value);
        });
    }
}

Aucun commentaire:

Enregistrer un commentaire