Git Product home page Git Product logo

oop-prototype-car's Introduction

Prototype Body Shop

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

Getting Started

  • Fork and clone this repository
  • Run npm install to install dependencies
  • npm test - run test suite
  • npm run lint:js - lint JS

Submission

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 install on Travis's servers
  • Run npm run lint:js to check your code styling
  • Run npm test to 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?

Phase I

Your Car should meet the following requirements:

  • Must have the following constructor parameters:
    • make
    • model
    • year
    • color
    • seats
  • By default, a new Car should have the following values initialized in the constructor:
    • previousOwners
      • should be initialized to an empty array, [].
    • owner
      • should be initialized to manufacturer.
    • running
      • should be initialized to false.
  • 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 owner and previousOwners array.
      • This takes 1 string parameter for the new owner's name.
      • The old owner should be pushed to the end of the previousOwners array.
      • The new owner should be set to the parameter passed in.
    • 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.

Phase II

Implement and test the following methods:

  • Car.start()
    • Should change the running value of the car to true.
  • Car.off()
    • Should change the running value to false.
  • 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.
  • 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.

Phase III

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 name and console.log that you are "driving to pick up <name>", but only if the car is running AND there are enough seats available.
    • Should also update the passengers array to include the new passenger.
    • Should also return true on success and false on failure.
    • The newly picked up passenger should be pushed to the end of the array.
  • Car.dropOff(name)
    • Should take a name and remove them from the passengers array, 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.
  • 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.


Licensing

  1. All content is licensed under a CC-BY-NC-SA 4.0 license.
  2. All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].

oop-prototype-car's People

Contributors

bhague1281 avatar kendradalley avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.