The idea of this lab is to get you comfortable with writing and implementing prototypes and constructors. We will also review testing in the lab.
Our car should have the following:
- make
- model
- year
- state
- color
- previous_owners
- current_owner
As a default a new Car
should have the following values:
- previous_owners should be an empty array,
[]
. - current_owner: should be the manufacturer (ford,honda,toyota).
state
should beoff
.
We should also be able to do the following with our car.
-
Car#sale
, we should be able to sell a car to someone, which should update thecurrent_owner
andprevious_owners
array. -
Car#paint
, which should take a new color and update the color of the car to be new color.
Implement and test the following methods:
Car#start
should change the state of the car toon
.Car#off
should change the state tooff
.Car#driveTo
, it shouldconsole.log
"driving to <destination>"
, but only if the carstate
ison
. Note: this method needs to take adestination
param.Car#park
only if the car isoff
and if it's off console.logparked!!
.
Add the following property to the constructor:
passengers
it should default to an empty array.
Implement the following methods:
Car#pick_up
should take aname
andconsole.log
that you are"driving to 'pick up <friend>'"
, but only if thecar
ison
. It should also update thepassangers
array to include the new passanger.Car#dropOff
it should take aname
and remove them from thepassengers
array, but only if they are in the array. It should also only drop them off if the car ison
.