OK. Here's the race game<script>
// I want to create a game in which one competitor can eliminate another. In this case, a spaceship "race." Kind of like something from "Star Wars." But because I still don't know what I'm doing, I'm trying to build a stupidly simple race game to start with. But my code is not running
function Spaceship(name, speed) {
this.name = name;
// Values 0 - 9 for speed
this.speed = speed;
this.position = 0;
alert("successfully set params")
}
this.advance = function() {
return this.position + this.speed;
alert("successfully set advance")
}
}
this.progressReport = function() {
return this.name + " is at " + this.position
}
}
var freighter = new Spaceship("Big Mac", 5, 4);
alert("successfully set Big Mac")
var battleship = new Spaceship("Warhorse", 2, 9);
alert("successfully set Warhorse")
var passengerLiner = new Spaceship("Space Duck", 7, 1);
alert("successfully set Space Duck")
var meters = 50;
alert("successfully set meters")
while ((freighter.position < meters && battleship.position < meters) && passengerLiner.position < meters) {
freighter.advance();
battleship.advance();
passengerLiner.advance();
alert(freighter.progressReport() + " | " + battleship.progressReport() + " | " passengerLiner.progressReport());
}
</script>