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.miles = 0;
- this.mileageType = _mileageType;
- 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
- // if (x > 0)
- // return x;
- // else return 0;
- if (x < 0)
- x = 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
- if (y > 0)
- return y;
- else return 0;
- };
- this.getTotalMileage = function() {
- // (4) complete this method for getting the total mileage
- // This method should return the total mileage as an integer
- if (mileageType == "net")
- miles = this.forward - this.reverse;
- else miles = this.forward + this.reverse;
- };
- }
- };
- // ***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();
- }
- console.log(solution(100, 10, "net")) //90
- console.log(solution(100, 10, "cumulative")) //110
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement