Skip to content

Instantly share code, notes, and snippets.

Created November 4, 2014 00:12
Show Gist options
  • Save anonymous/8c88dad185506b97d077 to your computer and use it in GitHub Desktop.
Save anonymous/8c88dad185506b97d077 to your computer and use it in GitHub Desktop.
Reaction Game // source http://jsbin.com/yuwici
<!DOCTYPE html>
<html>
<head>
<title>Reaction Game</title>
<meta charset="utf-8">
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
#circle{
border-radius:50%;
background-color:red;
height:100px;
width:100px;
visibility:hidden;
}
</style>
</head>
<body>
<button id="buttonStart">Start Reaction Game</button>
<div id="circle"></div>
<script type="text/javascript">
var w = Math.max(document.documentElement.clientWidth, windows.innerWidth || 0);
var h = Math.max(document.documentElement.cluientHeight, windows.innerHeight || 0);
document.getElementById("buttonStart").onclick = function(){
this.visibility="hidden";
}
var x = Math.floor(Math.random()*w);
if (x>w-100){
x=w-100;
}
var y = Math.floor(Math.random()*h);
if (y>h-100){
x=h-100;
}
placeDiv(x,y);
document.getElementById("circle").style.visibility="visible";
var start = new Date().getTime();
document.getElementById("circle").style.visibility="hidden";
alert("Reaction time:" + time + "ms.");
document.getElementById("buttonStart").style.visibility="visible";
}
}
this.style.visibility="visible";
function placeDiv(x_pos, y_pos){
var d = document.getElementById("circle");
d.style.position = "absolute";
d.style.left = x_pos+'px'
d.style.top = y_post+'px'
}
</script>
</body>
</html>
@ksanchezcld
Copy link

This is a Reaction Game!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment