Guest User

Untitled

a guest
Feb 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. <html>
  2.  
  3. </head>
  4.  
  5. <title>Reaction Timer</title>
  6.  
  7. <style type="text/css">
  8.  
  9. body {
  10.  
  11. font-family: sans-serif;
  12.  
  13. }
  14.  
  15. #shape {
  16.  
  17. width:200px;
  18. height:200px;
  19. background-color: red;
  20. display: none;
  21. position: relative;
  22.  
  23.  
  24. }
  25.  
  26. .bold {
  27.  
  28. font-weight: bold;
  29.  
  30. }
  31.  
  32.  
  33. </style>
  34.  
  35. <body>
  36.  
  37. <h1>Test Your Reactions!</h1>
  38.  
  39. <p>Click on the boxes and circles as quickly as you can, bitches!</p>
  40.  
  41. <p class="bold">Your time: <span id="timeTaken"></span></p>
  42.  
  43. <div id="shape"></div>
  44.  
  45. <script type = "text/javascript">
  46.  
  47. var start = new Date().getTime();
  48.  
  49. function getRandomColor() {
  50.  
  51. var letters = '0123456789ABCDEF'.split('');
  52.  
  53. var color = '#';
  54.  
  55. for (var i = 0; i < 6; i++) {
  56.  
  57. color += letters[Math.floor(Math.random() * 16)];
  58.  
  59. }
  60.  
  61. return color;
  62.  
  63. }
  64.  
  65. function makeShapeAppear() {
  66.  
  67. var top = Math.random() * 400;
  68.  
  69. var left = Math.random() * 400;
  70.  
  71. var width = (Math.random()* 200) + 100;
  72.  
  73. if (Math.random() > 0.5 {
  74.  
  75. document.getElementById("shape").style.borderRadius = "50%";
  76.  
  77. } else {
  78.  
  79. document.getElementById("shape").style.borderRadius = "0";
  80.  
  81. }
  82.  
  83. document.getElementById("shape").style.backgroundColor = getRandomColor();
  84.  
  85. document.getElementById("shape").style.width = width + "px";
  86.  
  87. document.getElementById("shape").style.height = width + "px";
  88.  
  89. document.getElementById("shape").style.top = top + "px";
  90.  
  91. document.getElementById("shape").style.left = left + "px";
  92.  
  93. document.getElementById("shape").style.display ="block";
  94.  
  95. start = new Date().getTime();
  96.  
  97. }
  98.  
  99. function appearAfterDelay() {
  100.  
  101. setTimeout(makeShapeAppear, Math.random() * 2000);
  102.  
  103. }
  104.  
  105. appearAfterDelay();
  106.  
  107. document.getElementById("shape").onclick = function() {
  108.  
  109. document.getElementById("shape").style.display = "none";
  110.  
  111. var end = new Date().getTime();
  112.  
  113. var timeTaken = (end - start) / 1000;
  114.  
  115. document.getElementById("timeTaken").innerHTML = timeTaken + "s";
  116.  
  117. appearAfterDelay();
  118.  
  119.  
  120. }
  121.  
  122.  
  123. </script>
  124.  
  125. </body>
  126.  
  127. </html>
Add Comment
Please, Sign In to add comment