No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download

README.md

General Assembly Logo

JS Finite State Machine Challenge

For this challenge, you will create a simple Finite-State Machine, represented by a SubwayGate.

Prerequisites

Instructions

  1. Fork and clone this repository.
  2. Change into the new directory.
  3. Install dependencies.
  4. Create and checkout a new branch to work on.
  5. Fulfill the listed requirements.

Starter code is available in lib/challenge.js. A pull request is not required, but it is necessary if you want a code review.

You may wish to refer to FAQs related to forking and cloning.

Requirements

Implement a SubwayGate constructor function that represents a Finite-State Machine. Each instance should have its own immutable _state property that starts as 'closed'. Each instance of SubwayGate should have access to five methods: state, tapCard, insertTicket, exit, and walkThrough.

Invoking the state method should return the value of _state.

The gate's _state should transition to 'open' only under three circumstances:

  • a charlieCard with a monthlyValue of true is tapped on the gate
  • a charlieTicket with a high enough value (2.25) is inserted into the gate
  • a person is exiting the station

The gate's _state should only transition to 'closed' when the walkThrough method is invoked.

While the gate's _state is 'open', tapping a card or inserting a ticket should not transition the state to 'closed', also no further value should be deducted from the ticket.

The tests will handle the creation of the charlieCard and charlieTicket which will look like so:

const charlieCard = {
  monthlyValue: Boolean
}

const charlieTicket = {
  value: Number
}

module.exports = {
  charlieCard,
  charlieTicket
}

You must use them as parameters to your tapCard and insertTicket methods.

Tasks

Developers should run these often!

  • grunt nag or just grunt: runs code quality analysis tools on your code and complains.
  • grunt test: runs any automated tests; may depend on grunt build.

License

  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 legal@ga.co.