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.
You want that after displaying the table, the script ask to enter a number again and again until the user will type -1?
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):
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!