Skip to content

Instantly share code, notes, and snippets.

@AnnemarieWegley
Created June 16, 2014 14:04
Show Gist options
  • Save AnnemarieWegley/f34341bdc6d18a25a31f to your computer and use it in GitHub Desktop.
Save AnnemarieWegley/f34341bdc6d18a25a31f to your computer and use it in GitHub Desktop.
<script>
var owl, cat, min;
function Animal(name, speed, focus) {
this.name= name;
this.speed=speed;
this.focus= focus;
this.position= 0;
this.run= function() {
if(Math.random() *10 < this.focus) {
this.position= this.position + this.speed;
}
}
}
owl= new Animal("Suzzie", 1, 10);
cat= new Animal("Kodi", 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);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment