-
-
Save brookr/58c70f52879ec38762a2 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 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