Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var autos = {
- car : function(_mileageType) {
- // (1) Add member variables here:
- // ie this.variableName = arg;
- // for storing the mileage and mileageType
- this.mileageType = _mileageType;
- this.f = 0;
- this.r = 0;
- this.forward = function (x) {
- // (2) complete this method for mileage driving forward
- // This method should log the forward mileage (x as an integer) and has no return value
- x > 0 ? f = x : f = 0;
- };
- this.reverse = function (y) {
- // (3) complete this method for mileage driving in reverse
- // This method should log the reverse mileage (y as an integer) and has no return value
- y > 0 ? r = y : r = 0;
- };
- this.getTotalMileage = function() {
- // (4) complete this method for getting the total mileage
- // This method should return the total mileage as an integer
- var miles;
- if (this.mileageType == "net")
- miles = f - r;
- else miles = f + r;
- return miles;
- };
- }
- };
- // ***Do not modify code below here***
- function solution(X, Y, U) {
- // Create a new car object
- var car = new autos.car(U);
- // Drive forward and reverse
- car.forward(X);
- car.reverse(Y);
- // Return the total mileage driven
- return car.getTotalMileage();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement