1

I have written down this code, for like a minigame with a password, and I want that if he writes the password right, or writes end, then it really ends, showing us a message, but in case he writes other stuff or nothing that it continues to ask, but It is not completely right.

 do{
                    var password = prompt("What is the password? Just give up by typing end, you won't find it, heheeh.")
                    if(password == "I11I1II1I"){
                        window.alert("Ok, ahha, so fun, going to the code, and searching for the password, yes yes yes good job, you won, yey")    
                    }
                    else if(password == "end"){
                        window.alert("Bye Bye, ehhe.")    
                    }
                    else{
                        window.alert("I don't know how you found me, but hey, you won't find the password, eehhehe.")
                    }
                }
                while((password == "") || (password != "I11I1II1I") || (password != "end"))

1
  • How is it "not completely right"? What's your outcome, what do you want to do with this code once is "completely right"? Commented Jun 17, 2017 at 16:48

2 Answers 2

1

You while logic is wrong, you should the prompt when password is "" or (password != "I11I1II1I" && password != "end")

do{
                password = prompt("What is the password? Just give up by typing end, you won't find it, heheeh.")
                if(password == "I11I1II1I"){
                    window.alert("Ok, ahha, so fun, going to the code, and searching for the password, yes yes yes good job, you won, yey") ;   
                }
                else if(password == "end"){
                    window.alert("Bye Bye, ehhe.")  ;
                }
                else{
                    window.alert("I don't know how you found me, but hey, you won't find the password, eehhehe.");
                }

            }
            while((password == "") || (password != "I11I1II1I" && password != "end"))

Sign up to request clarification or add additional context in comments.

Comments

1

You can use break (https://www.w3schools.com/js/js_break.asp):

while(true) {

    var password = prompt("What is the password? Just give up by typing end, you won't find it, heheeh.")

    if(password == "" || password == null) {
          // No password, just break or do something else
          break;
    }
    if(password === "I11I1II1I") {
          window.alert("Ok, ahha, so fun, going to the code, and searching for the password, yes yes yes good job, you won, yey");
          break;
    }
    else if(password === "end") {
          window.alert("Bye Bye, ehhe.");    
          break;
    }
    else {
          window.alert("I don't know how you found me, but hey, you won't find the password, eehhehe.")
    }
}

1 Comment

Thanks for your help, but still, one thing is still not fully working, because when i don't type anything, it just ends, which is not suppose. UPDATE: Oh Forget, i figured it out, I just tooked out the break;on the null section, thanks man for all, that link to w3schools was what made me think about this :).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.