Skip to content

Instantly share code, notes, and snippets.

@brmendez
Created June 17, 2014 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brmendez/f6766f02c880d7d0c76d to your computer and use it in GitHub Desktop.
Save brmendez/f6766f02c880d7d0c76d to your computer and use it in GitHub Desktop.
<script>
function Car(make, horsePower, weight){
this.make = make
this.horsePower = horsePower
this.weight = weight
this.distance = 0
this.traveled = function(){
return Math.floor((Math.random() * 10)) * horsePower / weight
}
}
var BMW = new Car("BMW", 320, 3240)
var AUDI = new Car("Audi", 298, 2980)
while (BMW.distance < 1000 && AUDI.distance < 1000){
BMW.distance += BMW.traveled()
AUDI.distance += AUDI.traveled()
console.log("BMW distance: " + BMW.distance + " AUDI.distance: " + AUDI.distance)
}
if (BMW.distance >= 1000)
alert(BMW.make + " Wins!")
else if(AUDI.distance >= 1000)
alert(AUDI.make + " Wins!")
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment