SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Loops not working - Help!

    Not sure why it not working correctly. Keeps hanging up when click on "Begin Drawing" and nothing populates in the Output. Thank you for your help.

    Here's my code:

    <html>
    <head>
    <title>Loops</title>

    <script type="text/javascript" src="random.js">
    </script>

    <script type="text/javascript">
    function Drawing()
    {
    //variable declarations
    var Pick,Picks;
    var Pick1,Pick2,Pick3,Pick4;
    var Roll1,Roll2,Roll3,Roll4;
    var Count;
    var Profit;

    //input section
    Pick1=parseFloat(document.LottoForm.txtPicks.value);
    Pick2=parseFloat(document.LottoForm.txtPicks.value);
    Pick3=parseFloat(document.LottoForm.txtPicks.value);
    Pick4=parseFloat(document.LottoForm.txtPicks.value);

    //calculations
    Count=0;
    while(Pick1!=Roll1 || Pick2!=Roll2 || Pick3!=Roll3 || Pick4!=Roll4)
    {
    Count++;

    Roll1=RandomInt(0,9);
    Roll2=RandomInt(0,9);
    Roll3=RandomInt(0,9);
    Roll4=RandomInt(0,9);
    }

    Profit=10000-Count;
    document.LottoForm.txtPicks.value=(Roll1+" "+Roll2+" "+Roll3+" "+Roll4);
    document.LottoForm.txtPicks.value=(Count);

    //output section
    document.LottoForm.txtPickOut.value=Pick.toFixed(2);
    document.LottoForm.txtPicksOut.value=Picks.toFixed(2);
    document.LottoForm.txtProfitOut.value=Profit.toFixed(2);

    }
    </script>
    </head>

    <body bgcolor="gold" style="color:darkblue">
    <u><h1 style="text-align:center">Pick-4 Lotto</h1></u>

    <form name="LottoForm" style="text-align:center">

    <br /><br />
    Pick-4 Lottery Number: <input type="text" name="txtPicks" size=5 value=""/>
    <input type="text" name="txtPicks" size=5 value=""/>
    <input type="text" name="txtPicks" size=5 value=""/>
    <input type="text" name="txtPicks" size=5 value=""/> Enter 4 Single-Digit Numbers

    <br /><br />
    Click on the button to perform Pick-4 drawing until sequence appear
    <br />
    <input type="button" value="Click Here to Begin Drawing" onClick="Drawing();"/>
    <br /><br />
    Number of Picks: <input type="text" name="txtPicksOut" size=10 value=""/>
    <br /><br />
    Pick: <input type="text" name="txtPickOut" size=10 value=""/>
    Net Profit: <input type="text" name="txtProfitOut" size=20 value=""/>

    </body>
    </html>

  2. #2
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're not addressing the form elements properly:

    Code:
    Pick1=parseFloat(document.LottoForm.txtPicks[0].value);
    Pick2=parseFloat(document.LottoForm.txtPicks[1].value);
    Pick3=parseFloat(document.LottoForm.txtPicks[2].value);
    Pick4=parseFloat(document.LottoForm.txtPicks[3].value);
    Also your form isn't closed.
    Tab-indentation is a crime against humanity.

  3. #3
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah! Thanks.

  4. #4
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure why the "Pick-4 Lottery Numbers" doesn't get transferred to the "Pick" box when clicked on button.
    Am I missing something?

    Code JavaScript:
    <html>  
    <head>
     
      <title>Loops</title>
     
      <script type="text/javascript" src="random.js">
      </script>
     
      <script type="text/javascript">
      function Drawing()
      {
      //variable declarations   
      var Picks;
      var Pick1,Pick2,Pick3,Pick4;
      var Roll1,Roll2,Roll3,Roll4;
      var Count;
      var Profit;
     
      //input section
      Pick1=parseFloat(document.LottoForm.txtPicks[0].value);
      Pick2=parseFloat(document.LottoForm.txtPicks[1].value);
      Pick3=parseFloat(document.LottoForm.txtPicks[2].value);
      Pick4=parseFloat(document.LottoForm.txtPicks[3].value);
     
      //calculations
      Count=0;
      while(Pick1!=Roll1 || Pick2!=Roll2 || Pick3!=Roll3 || Pick4!=Roll4)
      {
      Count++;
     
      Roll1=RandomInt(0,9);
      Roll2=RandomInt(0,9);
      Roll3=RandomInt(0,9);
      Roll4=RandomInt(0,9);
      }
     
      Profit=10000-Count;
      document.LottoForm.txtPicks.value=(Roll1+" "+Roll2+" "+Roll3+" "+Roll4);
      document.LottoForm.txtPicks.value=(Count);    
     
      //output section
      document.LottoForm.txtCountOut.value=Count.toFixed();
      document.LottoForm.txtProfitOut.value=Profit.toFixed(2);
     
      }
      </script>
      </head>
     
      <body bgcolor="gold" style="color:darkblue">
        <u><h1 style="text-align:center">Pick-4 Lotto</h1></u>
     
        <form name="LottoForm" style="text-align:center">
     
        <br /><br />
        Pick-4 Lottery Number: <input type="text" name="txtPicks" size=5 value=""/>
        <input type="text" name="txtPicks" size=5 value=""/> 
        <input type="text" name="txtPicks" size=5 value=""/>
        <input type="text" name="txtPicks" size=5 value=""/> Enter 4 Single-Digit Numbers
     
        <br /><br />
        Click on the button to perform Pick-4 drawings until sequence appears
        <br />
        <input type="button" value="Click Here to Begin Drawing" onClick="Drawing();"/>
        <br /><br />
        Number of Picks: <input type="text" name="txtCountOut" size=10 value=""/>
        <br /><br />
        Pick: <input type="text" name="txtPicksOut" size=10 value=""/>
        Net Profit: <input type="text" name="txtProfitOut" size=20 value=""/>
     
      </form>
      </body>
    </html>

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Your web browser should tell you that a function is missing from the above.
    Do you know where the JavaScript error console is for your web browser?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Your web browser should tell you that a function is missing from the above.
    Do you know where the JavaScript error console is for your web browser?
    That's the problem, no error is shown when I ran it and I'm using FireFox.

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jbinky View Post
    That's the problem, no error is shown when I ran it and I'm using FireFox.
    You saw no error in the Error Console?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    You saw no error in the Error Console?
    Nope. Everything works, but the Pick box didn't transfer from the top numbers boxes. That's why I'm confused.

  9. #9
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jbinky View Post
    Nope. Everything works, but the Pick box didn't transfer from the top numbers boxes. That's why I'm confused.
    That's odd, in my test is seems to have worked for me when a suitable randomInt function was in place.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #10
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    That's odd, in my test is seems to have worked for me when a suitable randomInt function was in place.
    Do you want to link us to a test web page where your problem can be experienced?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  11. #11
    SitePoint Member
    Join Date
    Feb 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Do you want to link us to a test web page where your problem can be experienced?
    I'm just running it off my laptop. This was my homework for school.

    Is there a test web page in this forum where I can do that? Because I will probably ask for more help when I have to do my final project.

  12. #12
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jbinky View Post
    I'm just running it off my laptop. This was my homework for school.

    Is there a test web page in this forum where I can do that? Because I will probably ask for more help when I have to do my final project.
    There are plenty of free web hosts, for example: 110mb.com

    What others do people recommend for free hosting?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #13
    SitePoint Enthusiast scout1idf's Avatar
    Join Date
    Nov 2009
    Location
    Ohio
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    There are plenty of free web hosts, for example: 110mb.com

    What others do people recommend for free hosting?
    I use Zymic.com.

    They provide a free domain name, php and mysql.

    The only support is forum based and live chat, but it's alright.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •