Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
693 B
0
Indexable
Never
function Car(Model, MilesPerGallon) {
  (this.Model = Model),
    (this.MilesPerGallon = MilesPerGallon),
    (this.tank = 0),
    (this.odometer = 0);
}
Car.prototype.fill = function (gallons) {
  this.tank += gallons;
  return this.tank;
};
Car.prototype.drive = function (distance, tank) {
  this.odometer += distance;
  tank = tank - distance / this.MilesPerGallon;
  if (tank <= 0) {
    return 'i RUNS OUT OF FUEL ' + this.odometer + ' miles';
  } else {
    return (
      'odometer is ' + this.odometer + ' miles and tank is ' + tank + ' gallons'
    );
  }
};
let newCar = new Car('maruti', 10);
let tank = newCar.fill(5);
console.log(newCar.drive(40, tank));