The idea of this lab is to get you comfortable with Object Oriented Programming (OOP) and introduce you to Test Driven Development (TDD) in JavaScript. By the end you should be comfortable working with objects and writing prototypes.
All of the tests have been written for you, so all you'll need to do is run them. No need to create any Car objects, because the tests will do that for you.
If any of the tests errors are unclear, take a look at what the test is running within test/carTest.js
- Fork and clone this repository
- Run
npm installto install dependencies npm test- run test suitenpm run lint:js- lint JS
To submit, create a pull request as before. Additionally, your submission will be checked automatically using a continuous integration service called Travis CI. Travis CI will do the following to check your code:
- Run
npm installon Travis's servers - Run
npm run lint:jsto check your code styling - Run
npm testto check if your tests pass
Make sure to run these commands locally first to verify your correctness. You can see the progress of the Travis CI check by going to your pull request, or looking at the Travis CI build page for this repo
##Requirements
We need a prototype for a car. Can you help us with your sweet JavaScript skills?
Your Car should meet the following requirements:
- Must have the following constructor parameters:
makemodelyearcolorseats
- By default, a new
Carshould have the following values initialized in the constructor:previousOwners- should be initialized to an empty array,
[].
- should be initialized to an empty array,
owner- should be initialized to
manufacturer.
- should be initialized to
running- should be initialized to
false.
- should be initialized to
- We should be able to do the following with our car:
Car.sell(newOwner)- We should able to sell a car to someone, which should update the
ownerandpreviousOwnersarray. - This takes 1 string parameter for the new owner's name.
- The old owner should be pushed to the end of the
previousOwnersarray. - The new
ownershould be set to the parameter passed in.
- We should able to sell a car to someone, which should update the
Car.paint(newColor)- We should be able to paint the car a new color
- This takes 1 string parameter for the new color's name
- This should update the color of the car to the new color.
Implement and test the following methods:
Car.start()- Should change the running value of the car to
true.
- Should change the running value of the car to
Car.off()- Should change the running value to
false.
- Should change the running value to
Car.driveTo(destination)- Should
console.log"driving to <destination>", but only if the car is running. - Should return true if it is successful and false if it is not.
- Should
Car.park()- Only if the car is not running, you should console.log
parked!!. - Should return true if it is successful and false if it is not.
- Only if the car is not running, you should console.log
Add the following property as a parameter to the constructor:
passengers- Should be optional and default to an empty array if not specified.
Implement the following methods:
Car.pickUp(name)- Should take a
nameandconsole.logthat you are"driving to pick up <name>", but only if thecaris running AND there are enough seats available. - Should also update the
passengersarray to include the new passenger. - Should also return true on success and false on failure.
- The newly picked up passenger should be
pushedto the end of the array.
- Should take a
Car.dropOff(name)- Should take a
nameand remove them from thepassengersarray, but only if they are in the array. - Should also only drop them off if the car is
on. - Should also output
"driving to drop off <name>"and return true on success and false on failure.
- Should take a
Car.passengerCount()- Should return the number (integer) of passengers currently in the car.
NOTE: When deciding if there are enough seats available, remember that the driver takes up 1 seat, but is NOT counted as a passenger in passengerCount(). You can assume the driver is the owner.
- All content is licensed under a CC-BY-NC-SA 4.0 license.
- All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact legal@ga.co.