Quote Originally Posted by shakazorba View Post
I will try to explain the problem with your while loop ...

the dom controls what you see in the browser

javascript can make changes to the dom

while javascript is running the dom does not change

the things that happen one by one in the loop
are not reflected in the dom, only the final state
is actually seen in the browser

Yeah, I get what you say. The reason, why I tried it like that was the following that worked somehow. Can you explain me, why this works?

Code:
   <p>How many fingers do I show?? </p>
   <p><input id="newGuess"/> <button id="newGuessButton"> Test your guess</button></p>

   <script>
      var i=0;
      var guess;
      var x;
      var control;
      var tries=1;
      document.getElementById("newGuessButton").onclick=function(callback){
         if (tries==1){
         x=Math.floor((Math.random()*5)+1);
         control=true;
         } 
         while (control){
            guess=document.getElementById("newGuess").value;
            if(x==guess){
               control=false;
            } else {
               control=true;
               alert("Wrong ")
               tries++;
               callback();
            };
         };
         alert("Correct! It took you " + tries + " tries.");
         tries=1;
      }
   </script>