mercredi 26 août 2015

Javascript - Basic if/else statement

I'm just learning JS and am confused as to why this if/else statement isn't going to the "else."

If you put in Monty or Chip, you get prompted for the password, if you put in Frank (or anything else) you STILL get prompted for the password, though it does say wrong login or password.

What am I missing to make it go to the "else" if you put in "Frank" or whatever as the login?

var password
var login = prompt('Enter your login.');


if (login === 'Monty' || 'Chip') {
    password = prompt('Enter your password.');
  if (login === 'Monty' && password === 'Cheese') {
    alert('Access Granted Monty');
  } else if (login === 'Chip' && password === 'Gadget') {
    alert('Access Granted Chip');
  } else {
    alert('Wrong login or password!');
  }
} else {
  alert('Wrong login!')
}

Aucun commentaire:

Enregistrer un commentaire