Answer to Question #295727 in HTML/JavaScript Web Application for chethan

Question #295727

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

  • the first line of input containing as string playerName
  • the second line of input containing as string Nitro
  • the third line of input containing as string speed

outputs

  • the output consists of multiple lines with the appropriate texts


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


1
Expert's answer
2022-02-09T14:49:56-0500
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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS