Class Vehicle
Здравейте!
Защо judge не ми приема задачата така? Не мога ли да използвам два конструктора?
https://pastebin.com/2aWpQnfM
Create a class with the name Vehicle that has the following properties:
- – a string
- – a string
- – an object that contains:
- – number (quality of the engine)
- – number
- – engine * power
- – a number
- – a function that receives fuel loss and decreases the fuel of the vehicle by that number
The constructor should receive the type, the model, the parts as an object, and the fuel
In judge post your class (Note: all names should be as described)
Example
Test your Vehicle class.
Input |
Output |
let parts = { engine: 6, power: 100 }; let vehicle = new Vehicle('a', 'b', parts, 200); vehicle.drive(100); console.log(vehicle.fuel); console.log(vehicle.parts.quality); |
100 600 |
let parts = {engine: 9, power: 500}; let vehicle = new Vehicle('l', 'k', parts, 840); vehicle.drive(20); console.log(vehicle.fuel); |
820 |
Благодаря ти, не ми беше ясен този синтаксис -
this.parts.quality = parts.engine * parts.power;
parts.quality =>
: )