Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions