Advertisement
Guest User

Untitled

a guest
May 20th, 2019
114
0
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.mileageType = _mileageType;
  7.         this.forward = function (x) {
  8.             // (2) complete this method for mileage driving forward
  9.             // This method should log the forward mileage (x as an integer) and has no return value
  10.             // if (x > 0)
  11.             //     return x;
  12.             // else return 0;
  13.             if (x < 0)
  14.                 x = 0
  15.         };
  16.         this.reverse = function (y) {
  17.             // (3) complete this method for mileage driving in reverse
  18.             // This method should log the reverse mileage (y as an integer) and has no return value
  19.             if (y > 0)
  20.                 return y;
  21.             else return  0;
  22.         };
  23.         this.getTotalMileage = function() {
  24.             // (4) complete this method for getting the total mileage
  25.             // This method should return the total mileage as an integer
  26.             var miles;
  27.             if (_mileageType == "net")
  28.                 miles = this.forward - this.reverse;
  29.             else miles = this.forward + this.reverse;
  30.             return miles;
  31.         };
  32.     }
  33. };
  34.  
  35. // ***Do not modify code below here***
  36. function solution(X, Y, U) {
  37.     // Create a new car object
  38.     var car  = new autos.car(U);
  39.     // Drive forward and reverse
  40.     car.forward(X);
  41.     car.reverse(Y);
  42.     // Return the total mileage driven
  43.     return car.getTotalMileage();
  44. }
  45.  
  46. console.log(solution(100, 10, "net")) //90
  47. console.log(solution(100, 10, "cumulative")) //110
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement