Last active
August 29, 2015 14:24
-
-
Save chrishamant/06a86b15d6fb69bb1071 to your computer and use it in GitHub Desktop.
A silly game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
function init(){ | |
var gameLength = 15000 // 15 seconds | |
var s = 0 // Number of clicks | |
var t = Date.now() //start time (in seconds since 1970) | |
var elm = document.getElementById("gamePiece") | |
elm.onclick = function(){ | |
s++ | |
var elapsed = Date.now() - t | |
if(elapsed < gameLength){ | |
elm.style.margin = elapsed % 300 + ' 0 0 ' + elapsed * 7 % 300 | |
}else{ | |
alert(s) //number of clicks at end of game | |
} | |
} | |
} | |
</script> | |
<body onload="init()"> | |
<img style="float:left" id="gamePiece" src="https://s-media-cache-ak0.pinimg.com/736x/fd/4d/74/fd4d74d5083647d78a68ce087b2e350c.jpg"> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment