Let's consolidate our knowledge of prototypes and constructors! This task has 3 parts.
The first part is to build base robot's constructor and his prototype according to the following requirements:
- BaseRobot function constructor takes
name
,weight
,coords
,chipVersion
and sets them for his instances; - BaseRobot prototype has methods
goForward
,goBack
,goRight
,goLeft
, which can takestep
prop or move the robot by 1 in the appropriate direction in the case whenstep
is undefined; - BaseRobot prototype has method
getInfo
, which returns a string in the formatRobot: %name%, Chip version: %chipVersion%, Weight: %weight%
;
The second part is to build flying robots constructor and his prototype according to the following requirements:
- FlyingRobot prototype inherits BaseRobot prototype;
- FlyingRobot constructor takes
name
,weight
,coords
,chipVersion
, and transmits them to BaseRobot constructor; - FlyingRobot constructor sets
z
coordinate tocoords
object of his instances; - FlyingRobot prototype has methods
goUp
andgoDown
, which can takestep
prop or move the robot by 1 in thez
coordinate in the case whenstep
is undefined; - The instance of FlyingRobot can use all methods from BaseRobot and FlyingRobot prototypes;
The third part is to build delivery drone constructor and his prototype according to the following requirements:
- DeliveryDrone prototype inherits FlyingRobot prototype;
- DeliveryDrone constructor takes
name
,weight
,coords
,chipVersion
, and transmits them to FlyingRobot constructor; - DeliveryDrone constructor takes
maxLoadWeight
,currentLoad
and sets it to his instances; - DeliveryDrone prototype has method
hookLoad
, which saved the load object tocurrentLoad
of DeliveryDrone instances ifweight
of cargo less thanmaxLoadWeight
of drone; - DeliveryDrone prototype has method
unhookLoad
, which sets initial valuenull
tocurrentLoad
; - The instance of DeliveryDrone can use all methods of BaseRobot, FlyingRobot, DeliveryDrone prototypes;
Delivery Robot schema:
deliveryRobot {
name: string
weight: number
chipVersion: number
maxLoadWeight: number
currentLoad: null || {
weight: number
description: string
}
coords: {
x: number
y: number
z: number
}
}
Read the guideline before start