Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

JS - Login condition example

0 votes
4 views
added Jul 6 in Javascript by LC Marshal First Warrant Officer (11,130 points)
edited 5 days ago by LC Marshal

If username as "admin", then prompt a password, if the input is empty, “Canceled.”, if it’s another string – then show “I don’t know you”.

The password is checked as follows:

  • If it equals “sacredpass”, then show “Welcome!”,
  • Another string – show “Wrong password”,
  • For an empty string or cancelled input, show “Canceled.”
let loginName = prompt('your login name', '');
  
if (loginName == 'admin') {
  let password = prompt('password','') 
    if (password == 'sacredpass') {
      alert('Welcome');
    } else if (password == '' || password == null) {
      alert('canceled');
    } else {
      alert('Wrong password')
    }
} else if (loginName == '') {
  alert('canceled')
}
else {
  alert('Dont know you')
}

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...