Advertisement
ambosdavid

x100 Times Tables

Mar 19th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>x100 Times Tables</title>
  6. <style>
  7. div {
  8. text-align:center;
  9. }
  10. body {
  11. background-color: black;
  12. }
  13. body,td,th {
  14. color: rgba(255,255,255,1);
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <div><h1>Press Any Key to Start</h1>
  20. <textarea style="height: 500px;" id="out"></textarea>
  21. <h3>See your favorite number up to x100!</h3></div>
  22. <script>
  23. var out = document.getElementById("out");
  24. var input = 0;
  25. window.addEventListener("keyup", function(e) {
  26. out.innerHTML = "";
  27. if (e.which == 82) {
  28. input = Math.floor(Math.random() * 1000);
  29. } else {
  30. input = prompt("What number?");
  31. }
  32. if (isNaN(input)) {
  33. out.innerHTML = "Input must only consist of numbers.";
  34. } else if (input == "") {
  35. out.innerHTML = "Input cannot be blank.";
  36. } else if (input == 0) {
  37. out.innerHTML = "Anything Multiplied by ZERO is ZERO.";
  38. } else if (input == null) {
  39. out.innerHTML = "Hitting Cancel won't do the trick. Please enter a value.";
  40. } else {
  41. for (var i = 1; i <= 100; i++) {
  42. out.innerHTML += input + " x ";
  43. if (i < 100) { out.innerHTML += " "; }
  44. if (i < 10) { out.innerHTML += " "; }
  45. out.innerHTML += i + " = ";
  46. if (input * i < 10000) { out.innerHTML += " "; }
  47. if (input * i < 1000) { out.innerHTML += " "; }
  48. if (input * i < 100) { out.innerHTML += " "; }
  49. if (input * i < 10) { out.innerHTML += " "; }
  50. out.innerHTML += (input * i) + "\n";
  51. }
  52. }
  53. });
  54. </script>
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement