Skip to content

Instantly share code, notes, and snippets.

@Beneboe
Created February 12, 2013 12:26
Show Gist options
  • Save Beneboe/4761993 to your computer and use it in GitHub Desktop.
Save Beneboe/4761993 to your computer and use it in GitHub Desktop.
testing in js
console.log("\n");
var i = 10;
function writeD(d){
document.write(d);
}
function fixDecimal(num) {
return Math.round(num * 10) / 10;
}
function Timer (milisecs, callback) {
var t;
this.runs = false;
this.start = function() {
this.runs = true;
t = setInterval(function () {callback();}, milisecs);
};
this.stop = function () {
clearTimeout(t);
this.runs = false;
};
}
var apple = new Timer(100, function () {
if (i > 0){
i -= 0.1;
i = fixDecimal(i);
}
else{
apple.stop();
}
writeD(i + " ");
});
apple.start();
//setTimeout(function () {apple.stop();}, 5100);
setInterval(function () {console.log(apple.runs);}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment