CodePlayer
HTML
CSS
JavaScript
Output
Lets check how fast you are.
Click on the boxes and circles to check your reaction time.
body { font-family: sans-serif; margin-left: 2em; height: 90vh; } #box { width: 200px; height: 200px; background-color: blue; display: none; position: relative; }
function getRandomColor() { var letters = "0123456789ABCDEF".split(''); var color = "#"; for (var i = 0; i < 6; i++) { color += letters[Math.round(Math.random() * 15)]; } return color; } var clickedTime; var createdTime; var reactionTime; function makeBox() { var time = Math.random(); time = time * 1000; setTimeout(function () { if (Math.random() > 0.6) { document.getElementById("box").style.borderRadius = "100px"; } else if(Math.random() > 0.3){ document.getElementById("box").style.borderRadius = "50px"; } else { document.getElementById("box").style.borderRadius = "0px"; } var top = Math.random(); top = top * 350; var left = Math.random(); left = left * 1000; document.getElementById("box").style.top = top + "px"; document.getElementById("box").style.left = left + "px"; document.getElementById("box").style.backgroundColor = getRandomColor(); document.getElementById("box").style.display = "block"; createdTime = Date.now(); }, time); } document.getElementById("box").onclick = function () { clickedTime = Date.now(); reactionTime = (clickedTime - createdTime) / 1000; document.getElementById("reactionTime").innerHTML = "Reaction Time is: " + reactionTime + "seconds"; this.style.display = "none"; makeBox(); } makeBox();