1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

What am i doing wrong?

Discussion in 'JavaScript' started by demondestiny, Sep 7, 2010.

  1. #1
    Hi i'm developing a javascript program that requires the user to input a number and then displays all times tables from that number. I've got all that working but i need it so that it continuously keeps displaying times tables until the user types -1.

    
    <html>
      <head>
        <title>Times Tables</title>
          <style type="text/css">
            body {
                  background-color:#000000;
                  color:#FFFFFF;
                  font-size:30;
                  text-align:center;
                 }
          </style>
      </head>
      <body>
        <script type="text/javascript">
        var limit, count, equals;
        count = 0;
        document.write("<h1>Times Tables</h1>");
        limit = prompt("Enter a number", "");
        if (limit == null)
       {
        document.write("You clicked cancel. There will be no numbers displayed");
       }
       else if (limit == "")
       {
        document.write("Please enter a number");
       }
       else if (limit != parseInt(limit))
       {
        document.write("Must be a valid number");
       }
       else
       {
         while (count <= 12)
         {
         equals = parseInt(limit) * parseInt(count);
         document.write (limit + " * " + count + " = " + equals);
         count = parseInt(count) + 1;
         document.write("<br /><br />");
         }
         }
    
       document.write("<br /><br />");
       document.write("<input type='button' value='Do Another One' onclick='window.location.reload()'");
       </script>
    
      </body>
     </html>
    
    Code (markup):
    Anyone tell me how i would go about doing this? Many thanks for any help given.
     
    demondestiny, Sep 7, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    You want that after displaying the table, the script ask to enter a number again and again until the user will type -1?
     
    s_ruben, Sep 7, 2010 IP
  3. demondestiny

    demondestiny Peon

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes i do. Thanks :)
     
    demondestiny, Sep 7, 2010 IP
  4. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #4
    Do you want this?

    
    <html>
      <head>
        <title>Times Tables</title>
          <style type="text/css">
            body {
                  background-color:#000000;
                  color:#FFFFFF;
                  font-size:30;
                  text-align:center;
                 }
          </style>
      </head>
      <body>
        <script type="text/javascript">
        function xxx(){
            var limit, count, equals;
            count = 0;
            document.write("<h1>Times Tables</h1>");
            limit = prompt("Enter a number", "");
            if (limit == null)
           {
            document.write("You clicked cancel. There will be no numbers displayed");
           }
           else if (limit == "")
           {
            document.write("Please enter a number");
           }
           else if (limit != parseInt(limit))
           {
            document.write("Must be a valid number");
           }
           else
           {
             while (count <= 12)
             {
             equals = parseInt(limit) * parseInt(count);
             document.write (limit + " * " + count + " = " + equals);
             count = parseInt(count) + 1;
             document.write("<br /><br />");
             }
    
             if(limit!=-1){
                xxx();
             }
    
             }
        }
    
        xxx();
    
        document.write("<br /><br />");
           document.write("<input type='button' value='Do Another One' onclick='window.location.reload()'");
       </script>
    
      </body>
     </html>
    
    Code (JavaScript):
     
    s_ruben, Sep 7, 2010 IP
    demondestiny likes this.
  5. demondestiny

    demondestiny Peon

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks it wasn't exactly what i was after but i tweaked it a bit and it's working fine :)

    Cheers for the help +rep!
     
    demondestiny, Sep 7, 2010 IP