Question: //JavaScript The Exercise class will have 2 instance properties. One will be named activity and will reference one of the exercise function objects. For Example:

//JavaScript

The Exercise class will have 2 instance properties. One will be named activity and will reference one of the exercise function objects. For Example:

 this.activity = new walking(); 

//Created activity instance need help with second instance which is type

The other will be named type and will hold the name of the activity. Inside the constructor, check the string parameter's value. If it is "walking" create an instance of walking exercise object and assign it to the activity instance property, if it is "running" create and assign an instance of the running exercise object, else throw an error. Finally, create an instance property named type (if you haven't already done so ) and set its value to be the value of the parameter.

d) Add a function named calculate to the Exercise class. The function accepts "weight" and "distance" parameters. It will pass these values to the object's activity's calculate function and returns the value.

This would be called by writing something like

 this.activity.calculate(weight, distance); 

//this is the start of the file code

var walking = function(){

this.calculate = function (weight, distance){

return 0.3 * weight * distance;

}

};

//requires weight in lbs, and distance in miles

var running = function(){

this.calculate = function (weight, distance){

return 0.63 * weight * distance;

}

};

class Excercise{

constructor(activity){

this.activity = new walking();

}

}

module.exports = Excercise;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!