title: javascript lottery game using random numbers what is wrong with my logic
body: <p>A simple straight forward game user enters 6 numbers and clicks button play, if all 6 numbers are matched they win lottery, I have set up the loop so that it keeps generating a random numbers until the user wins, then informs them the number of loops it took to get to winning numbers.  My problem with logic is that the loop terminates even if one number is matched I need it to keep running until all numbers are matched.  Here is the code please help so that I can lean :)</p>
  
  <pre><code> &lt;html&gt;
   &lt;head&gt;
   &lt;title&gt;Lottery Game&lt;/title&gt;
   &lt;SCRIPT LANGUAGE="javascript"&gt;
  
   function genNums(){
  
   var counter = 0;
  
      do{
  
      var num1 = Math.round(59 * Math.random())+1
      var resultnum1 = document.lottery.Rball1.value = num1
  
      var num2 = Math.round(59 * Math.random())+1
      var resultnum2 =document.lottery.Rball2.value = num2
  
      var num3 = Math.round(59 * Math.random())+1
      var resultnum3 =document.lottery.Rball3.value = num3
  
      var num4 = Math.round(59 * Math.random())+1
      var resultnum4 =document.lottery.Rball4.value = num4
  
      var num5 = Math.round(59 * Math.random())+1
      var resultnum5 =document.lottery.Rball5.value = num5
  
      var num6 = Math.round(59 * Math.random())+1
      var resultnum6 =document.lottery.Rball6.value = num6
  
      var enterednum1 = document.lottery.ball1.value;
      var enterednum2 = document.lottery.ball2.value;
      var enterednum3 = document.lottery.ball3.value;
      var enterednum4 = document.lottery.ball4.value;
      var enterednum5 = document.lottery.ball5.value;
      var enterednum6 = document.lottery.ball6.value;
  
      counter = counter + 1;
  
  }while(resultnum1 != enterednum1 &amp;&amp; resultnum2 != enterednum2 &amp;&amp; resultnum3 != enterednum3 &amp;&amp; resultnum4 != enterednum4 &amp;&amp; resultnum5 != enterednum5 &amp;&amp; resultnum6 != enterednum6)
  
  
  //alert(counter);
  
  if(resultnum1 == enterednum1 &amp;&amp; resultnum2 == enterednum2 &amp;&amp; resultnum2 == enterednum2 &amp;&amp; resultnum2 == enterednum2 &amp;&amp; resultnum2 == enterednum2 &amp;&amp; resultnum2 == enterednum2){
  
      alert("JackPot!, You Won The Lottery");
      alert("It took " + counter + " number of loops to get wining numbers")
      document.bgColor = "lightblue";
  
  }
  else{
      alert("sorry you did not win" + counter);
  }
  
  
   }
  
  &lt;/SCRIPT&gt;
  
  
  
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;Form Name = "lottery"&gt;
  
  Lottery Game&lt;br/&gt;
  
  Please enter your six numbers below:&lt;br/&gt;
  
  Ball#1 &lt;Input Type = "text" size = "1" value = "7" name = "ball1"&gt;&lt;br/&gt;
  Ball#2 &lt;Input Type = "text" size = "1" value = "45" name = "ball2"&gt;&lt;br/&gt;
  Ball#3 &lt;Input Type = "text" size = "1" value = "29" name = "ball3"&gt;&lt;br/&gt;
  Ball#4 &lt;Input Type = "text" size = "1" value = "10" name = "ball4"&gt;&lt;br/&gt;
  Ball#5 &lt;Input Type = "text" size = "1" value = "5" name = "ball5"&gt;&lt;br/&gt;
  Ball#6 &lt;Input Type = "text" size = "1" value = "25" name = "ball6"&gt;&lt;br/&gt;
  
  
  &lt;Input Type = "button" value = "Play" onClick = "genNums()"&gt;&lt;br/&gt;
  
  Results:&lt;br/&gt;
  
  Result Ball#1 &lt;Input Type = "text" size = "1" name = "Rball1"&gt;&lt;br/&gt;
  Result Ball#2 &lt;Input Type = "text" size = "1" name = "Rball2"&gt;&lt;br/&gt;
  Result Ball#3 &lt;Input Type = "text" size = "1" name = "Rball3"&gt;&lt;br/&gt;
  Result Ball#4 &lt;Input Type = "text" size = "1" name = "Rball4"&gt;&lt;br/&gt;
  Result Ball#5 &lt;Input Type = "text" size = "1" name = "Rball5"&gt;&lt;br/&gt;
  Result Ball#6 &lt;Input Type = "text" size = "1" name = "Rball6"&gt;&lt;br/&gt;
  
  
  &lt;/Form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>