javascript - Request for the username and password again if either is wrong -
how make when password and/or username wrong ask password and/or username again?
var user = prompt("please enter username continue.").touppercase(); if (user === "ryebread4") { var pass = prompt("please enter password continue").touppercase(); if (pass === "7277") { console.log("welcome ryebread4"); } else { console.log("username or password incorrect! please try again"); } }
use while
loop
var signedin = false; while(!signedin) { ... if (password === "7477") { console.log("welcome back!"); signedin = true; } ... }
or for
(not recommend)
var username = ""; var password = ""; for(;username !== "ryebread4" && password !== "7477";) { //prompt user username/password ... }
that same methodology can applied while
loop, , eliminate variable.
Comments
Post a Comment