Created
February 11, 2015 07:46
-
-
Save ckotsovos/28bd956705722afe10dc to your computer and use it in GitHub Desktop.
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
<script> | |
var Animal = function(n, s, f) { | |
this.name = n; | |
this.speed = s; | |
this.focus = f; | |
this.positon = 0; | |
this.report = function() { | |
return this.name + " is at " + this.positon; | |
}; | |
this.run = function() { | |
if(this.focus < (Math.random() * 10)) { | |
this.positon += this.speed; | |
} | |
}; | |
} | |
//Turtle vs. Rabbit vs. Every Fictional high speed animal | |
var turtle = new Animal("TimmyPete", 5, 5), | |
rabbit = new Animal("Mopsy", 5, 5), | |
hedgehog = new Animal("Sonic", 5, 4), | |
mouse = new Animal("Speedy", 6, 4), | |
snail = new Animal("Turbo", 5, 5), | |
bird = new Animal("RoadRunner", 6, 4), | |
cat = new Animal("Cheetara", 5, 5); | |
//Increasing the distance gives everybody a fair chance | |
var distance = 100; | |
while(turtle.positon < distance && rabbit.positon < distance && hedgehog.positon < distance && mouse.positon < distance && snail.positon < distance && bird.positon < distance && cat.positon < distance) { | |
turtle.run(); | |
rabbit.run(); | |
hedgehog.run(); | |
mouse.run(); | |
snail.run(); | |
bird.run(); | |
cat.run(); | |
}; | |
console.log(turtle.report()); | |
console.log(rabbit.report()); | |
console.log(hedgehog.report()); | |
console.log(mouse.report()); | |
console.log(snail.report()); | |
console.log(bird.report()); | |
console.log(cat.report()); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For some reason the indent goes wacky when it transfer over to git. I have no idea whats causing this.