Skip to content

Instantly share code, notes, and snippets.

@brookr
Forked from petemmitchell/usaWins.html
Last active August 29, 2015 14:02
Show Gist options
  • Save brookr/58c70f52879ec38762a2 to your computer and use it in GitHub Desktop.
Save brookr/58c70f52879ec38762a2 to your computer and use it in GitHub Desktop.
<script>
var usa, ghana, portugal, germany, miles;
function Racer(name, speed, intelligence, luck) {
this.name = name;
this.speed = speed;
this.intelligence = intelligence;
this.luck = luck;
this.position = 0;
this.race = function() {
if (Math.random() * 10 < intelligence){
this.position = (this.position + (this.speed * luck));
}
}
this.report = function() {
return this.name + "-" + this.position + " ";
}
}
usa = new Racer("Dempsey", 4, 8, 2);
ghana = new Racer("Asamoah", 3, 5, 1.75);
portugal = new Racer("Ronaldo", 10, 2, 1);
germany = new Racer("Ozil", 5, 7, 1.25);
miles = 100;
while (usa.position < miles && ghana.position < miles && portugal.position < miles && germany.position < miles) {
usa.race();
ghana.race();
portugal.race();
germany.race();
console.log(usa.report() + ghana.report() + portugal.report() + germany.report());
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment