Created
February 12, 2013 12:26
-
-
Save Beneboe/4761993 to your computer and use it in GitHub Desktop.
testing in js
This file contains hidden or 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
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