Code Monkey home page Code Monkey logo

hw-week_01-day_05-mta's Introduction

MTA Puzzle

Objectives:

  • Apply your knowledge of JavaScript to solve a real world problem.
  • Get really good at array manipulation.

Activity

  • Create a program that models a simple subway system.

  • The program takes the line and stop that a user is getting on at and the line and stop that user is getting off at and prints the journey and the total number of stops for the trip in the console:

planTrip("N", "Times Square", "6", "33rd"); // This is only a suggested function name and signature.

// console.log() shows output similar to this:
// "You must travel through the following stops on the N line: 34th, 28th, 23rd, Union Square."
// "Change at Union Square."
// "Your journey continues through the following stops: 23rd, 28th, 33rd."
// "7 stops in total."
  • There are 3 subway lines:
    • The N line has the following stops: Times Square, 34th, 28th, 23rd, Union Square, and 8th
    • The L line has the following stops: 8th, 6th, Union Square, 3rd, and 1st
    • The 6 line has the following stops: Grand Central, 33rd, 28th, 23rd, Union Square, and Astor Place.
    • All 3 subway lines intersect at Union Square, but there are no other intersection points. (For example, this means the 28th stop on the N line is different than the 28th street stop on the 6 line, so you'll have to differentiate this when you name your stops in the arrays.)
  • Tell the user the number of stops AND the stops IN ORDER that they will pass through or change at.

Hints:

  • Work out how you would do it on paper first! Then start to explain that process in JavaScript.
  • Focus on a single line before trying to tackle multiple lines!!
    • Hint: A multiple line trip could be considered two single line trips
  • Don't worry about prompting the user for input. Hard code some values to get it working. You can use prompt() later, if you want, to make it more interactive.
  • Consider drawing the lines by sketching out the subway lines and their stops and intersection.
  • The key to the lab is finding the index positions of each stop. (hint: .indexOf() and .includes())

hw-week_01-day_05-mta's People

Contributors

sara0alyahya avatar mfalthaw avatar

Watchers

James Cloos 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.