2017-06-17 3 views
1

Ich habe diesen Code geschrieben, für wie ein Minispiel mit einem Passwort, und ich will, dass, wenn er das Passwort richtig schreibt, oder schreibt Ende, dann endet es wirklich, zeigt uns eine Nachricht, aber für den Fall Er schreibt andere Sachen oder nichts, was er weiter fragt, aber es ist nicht völlig richtig.Javascript Algorithmus Fehler 3

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"))

+0

Wie ist es "nicht ganz richtig"? Was ist Ihr Ergebnis, was möchten Sie mit diesem Code einmal tun, ist "völlig richtig"? – Lixus

Antwort

1

Sie während Logik falsch ist, sollten Sie die Eingabeaufforderung, wenn Passwort "" oder (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"))

1

Sie können break (https://www.w3schools.com/js/js_break.asp) verwenden:

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.") 
    } 
} 
+0

Vielen Dank für Ihre Hilfe, aber immer noch, eine Sache funktioniert immer noch nicht, denn wenn ich nichts eintippe, endet es einfach, was nicht angenommen wird. UPDATE: Oh Vergiss es, ich habe es herausgefunden, ich habe einfach die Pause entfernt, auf der Null-Sektion, danke Mann für alle, dieser Link zu w3schools hat mich dazu gebracht, darüber nachzudenken :). –