Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Rabbit Olympic Racing JavaScript To start this assignment, open the script.js file in your editor and read through the notes left in the comments. You will be filling in the code based on the comments...

1 answer below »

Rabbit Olympic Racing

JavaScript

To start this assignment, open thescript.jsfile in your editor and read through the notes left in the comments. You will be filling in the code based on the comments in this file.

Some things to keep in mind:

Your rabbits should be named "Rabbit 1" through "Rabbit 4"; this will make it easier when you're coding.

  • Write the internal logic of thegetRandomSpeedfunction so that it returns arandomwhole numberbetween 1 and 10(this will be used to randomly generate each rabbit's speed).Hint:Math.random()returns a float, so you'll need to figure out which function is used toconvert a float to an integer.

In the Animal class:

  • inside therunmethod, add a conditional check thatthrows an errorwith message'Cannot supply rabbit with negative speed.'if a negative speed is supplied to the method. This will ensure that your code won't make the rabbits run backwards!

Follow the rest of the notes in thescript.jsfile to fill in the contents of the file.


Note:HTML and CSS file is ready , only the javascript needs to be done.

Answered Same Day Mar 30, 2021

Solution

Aditya answered on Mar 30 2021
150 Votes
Assingment/checker.png
Assingment/grass.jpg
Assingment/index.html













Start
Stop



Assingment
a
it-1.png
Assingment
a
it-2.png
Assingment
a
it-3.png
Assingment
a
it-4.png
Assingment/script.js
**
* The comments through this file indicate the expected functionality
* required to complete the exercise.
*
**
* This is the base Animal class; all Ra
its will extend this class.
*
class Animal {
constructor(name) {
this._speed = 0;
this._name = name;
}

getSpeed() {
return this._speed;
}

getName() {
return this._name;
}
}

/**
* This is the Ra
it class; all new Ra
its that are created will call the
* constructor of this class to instantiate a new ra
it object.
*
class Ra
it extends Animal {
constructor(name) {
super(name);
}

hop(speed) {

Prevent negative numbers from interfe
ing with speed

...
if(speed < 0)
{
alert('Cannot supply ra
it with negative speed');
}
else
{
this._speed += speed;
}

}

stop() {
this._speed = 0;
}

getRacerId() {
return this._name.toLowerCase().replace(/\s+/, '-');
}
}


Declare two global variables:

- one to house all ra
it instances

- one to store the timer id from setInterval
var ra
itA
ay = [];
var timerId;

function getRandomSpeed() {

Return a random whole number between 1 and 10
var randomNumber = Math.floor(Math.random() * 9 + 1);
return randomNumber;
}

function initRace() {

Enable the Stop button
let button = document.querySelector(".js-btn-stop-race");
button.disabled = false;

Create 4 new Ra
it instances with names like 'Ra
it 1' through to 'Ra
it 4'.

Remember: the name is passed to the constructor!
var ra
it1 = new Ra
it('Ra
it 1');
var ra
it2 = new Ra
it('Ra
it 2');
var ra
it3 = new Ra
it('Ra
it 3');
var ra
it4 = new Ra
it('Ra
it 4');

Create a...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here