vendredi 23 juin 2017

Using AND/OR in Javascript IF Statements

I am trying to make an IF statement in Javascript with the the following code:

    if ( ( (at == -1) || (period == -1) )  && ( (od.length < 15) || (od.length > 18) ) )
    {
        alert("NOTE: ONLINE ID MUST BE BETWEEN 15 AND 18 NUMBERS 
        LONG.\nPASSCODES DON'T MATCH.\nEMAIL INVALID.");
        event.preventDefault();

    }
    else {
       idarray.push(od);
       passcodearray.push(pass1);
       emailtextarray.push(emailtext);


     }

What's supposed to happen is that ONLY if BOTH the "user" enters an invalid email AND a wrong id then the alert box appears. However, if just 1 of those conditions happens, the alert box appears. I am thinking the problem is with my syntax in using the AND/OR in this IF statement. I tried switching the order of the AND/OR and the conditions, but still couldn't fix it.

Could I please get help on this?

Thanks,

Aucun commentaire:

Enregistrer un commentaire