Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
50 lines (31 sloc) 2.49 KB

General Assembly Logo

JS Finite State Machine Challenge

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



  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.


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

The gate's state should transition to open 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, you should use them as parameters to your methods. They will be objects and their keys are mentioned above.


Developers should run these often!

  • grunt nag or just grunt: runs code quality analysis tools on your code and complains.
  • grunt make-standard: reformats all your code in a standard style.
  • grunt test: runs any automated tests; may depend on grunt build.


  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