mardi 29 octobre 2019

how do I use operational operators with 3 variables?

I have 3 input fields with text. I want to use an if statement with logical operators to check if any of the input fields are blank, but I can't use or(||) for the 3 variables.

What is the right way to use logical operators?

let name = $("#name").val();
let email = $("#email).val();
let color = $("#color).val();

if(name == '' && ( email == '' || color == '') {
  console.log("please complete form");
 }
else {
//submit data
}

the code works as desired if I leave the name field blank, but because name is true the if statement accepts it. How can I make it so the if statement checks if any of the input fields are blank?

Aucun commentaire:

Enregistrer un commentaire