• API
• FAQ
• Tools
• Archive
SHARE
TWEET

Untitled

a guest May 20th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. var autos = {
2.     car : function(_mileageType) {
3.         // (1) Add member variables here:
4.         // ie this.variableName = arg;
5.         // for storing the mileage and mileageType
6.         this.miles = 0;
7.         this.mileageType = _mileageType;
8.         this.forward = function (x) {
9.             // (2) complete this method for mileage driving forward
10.             // This method should log the forward mileage (x as an integer) and has no return value
11.             // if (x > 0)
12.             //     return x;
13.             // else return 0;
14.             if (x < 0)
15.                 x = 0
16.         };
17.         this.reverse = function (y) {
18.             // (3) complete this method for mileage driving in reverse
19.             // This method should log the reverse mileage (y as an integer) and has no return value
20.             if (y > 0)
21.                 return y;
22.             else return  0;
23.         };
24.         this.getTotalMileage = function() {
25.             // (4) complete this method for getting the total mileage
26.             // This method should return the total mileage as an integer
27.             if (mileageType == "net")
28.                 miles = this.forward - this.reverse;
29.             else miles = this.forward + this.reverse;
30.         };
31.     }
32. };
33.
34. // ***Do not modify code below here***
35. function solution(X, Y, U) {
36.     // Create a new car object
37.     var car  = new autos.car(U);
38.     // Drive forward and reverse
39.     car.forward(X);
40.     car.reverse(Y);
41.     // Return the total mileage driven
42.     return car.getTotalMileage();
43. }
44.
45. console.log(solution(100, 10, "net")) //90
46. console.log(solution(100, 10, "cumulative")) //110
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top