Skip to content

Instantly share code, notes, and snippets.

@PlenipotentSS
Forked from AnnemarieWegley/OwlCat
Last active August 29, 2015 14:02
Show Gist options
  • Save PlenipotentSS/9200f558f8320a1c1c84 to your computer and use it in GitHub Desktop.
Save PlenipotentSS/9200f558f8320a1c1c84 to your computer and use it in GitHub Desktop.
<script>
var owl, cat, whowins, winner;
whowins= prompt("Guess who will the tootsie pop contest, Owl or Cat?");
function Animal(name, speed, focus){
this.name= name;
this.speed=speed;
this.position=0;
this.focus= focus;
this.run= function(){
if(Math.random() *10 < this.focus) {
this.position= this.position + this.speed;
}
}
}
owl= new Animal("Owl", 1, 10);
cat= new Animal("Cat", 4, 2);
min=20;
while (owl.position <min && cat.position < min){
owl.run();
cat.run();
console.log(owl.name + " : " + owl.position + " , " + cat.name + " : " + cat.position);
}
if (owl.position > cat.position) {
winner = owl
} else {
winner = cat
}
if (whowins == winner.name) {
alert("you guessed right!")
} else {
alert("better luck next time!")
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment