the goal of this code is quickly to get off the ground with classes.
given playerName, Nitro and speed are inputs write a super class Race with property and methods
inputs
outputs
sample input1
Alyssa
100
sample output1
Race has started
speed 50; Nitro 50
speed 70; Nitro 60
Alyssa is the winner
speed 0; Nitro 60
sample input2
Joel
100
100
sample output2
Race has started
speed 150; Nitro 50
speed 170; Nitro 60
Joel is the winner
speed 0; Nitro 60
class Race {
constructor(playerName, nitro, speed) {
this.playerName = playerName;
this.nitro = nitro;
this.speed = speed;
}
boostSpeed() {
this.speed = this.speed + 50;
this.nitro = this.nitro - 50;
}
ride() {
this.speed = this.speed + 20;
this.nitro = this.nitro + 10;
}
stopRace() {
this.speed = 0;
}
speedAndNitroMessage() {
console.log(`speed ${this.speed} nitro ${this.nitro}`)
}
winMessage () {
console.log(`${this.playerName} is the winner`)
}
startRace() {
console.log('Race has started')
this.boostSpeed()
this.speedAndNitroMessage()
this.ride()
this.speedAndNitroMessage()
this.winMessage()
this.stopRace()
this.speedAndNitroMessage()
}
}
const race = new Race('Alina', 100, 0);
race.startRace()
Comments
Leave a comment