Giter VIP home page Giter VIP logo

js-basics-functions-lab-web-103017's Introduction

Functions Lab

Objectives

  1. Practice writing functions
  2. Explain calling functions from within other functions
  3. Practice basics of control flow and return statements

Introduction

Scuber has gained some traction among mom's and dad's in New York City. It also has received a few requests.

First, Scuber's CTO wants to ensure that its headquarters is near its customers. It asks you to write a function that takes in a pickup location for a passenger, and returns the number of blocks from it's headquarters on 42nd street. This can be used for another function that translates the number of blocks from headquarters to the distance in feet.

Second, customers want Scuber to calculate the number of feet traveled based on the distance. Write a function called calculateVertical that takes in the beginning and destination blocks and returns the number of feet travelled. Each block in Manhattan is 264 feet long. For example calculateVertical(34, 38) returns 1056 ((38-34)*264). You can assume that we are only calculating vertical distance from headquarters. So the functions won't return a different distance from 45th street and Lexington Avenue and 45th street and Broadway - it's only calculating the vertical distance.

Instructions

If you run learn you will see the tests that are breaking and that you will be working to fix. It's easier to understand and solve the problem if you look through the tests, which are located in test/indexTest.js. After the word describe, you will see the name of the function that the test is testing, for example the first function tested is distanceFromHqInBlocks. Then in after the word it you can see the specifications of the function. The test literally calls the function that you write in index.js. So the first test will call your declared function distanceFromHqInBlocks and pass through an argument of 43.

  • distanceFromHqInBlocks: Returns the number of blocks from Scuber's headquarters to the pickup location.

  • distanceFromHqInFeet: Returns the number of blocks from Scuber's headquarters to the pickup location. Note that you can use your distanceFromHqInBlocks function to help return the correct value here. Here is an example of how to do this:

function distanceFromHqInBlocks () {

}

function distanceFromHqInFeet () {
  distanceFromHqInBlocks();
  // calls distanceFromHqInBlocks from inside the distanceFromHqInFeet function
}
  • distanceTravelledInFeet: Calculates the number of feet a passenger travels given a starting block and an ending block - it only calculates distance North and South. It uses the knowledge that a block is 264 feet long.

  • calculatesFarePrice: Given the same starting and ending block, return the fare for the customer. The first four hundred feet are free. For a distance between 400 and 2000 feet, the price is 2 cents per foot. Then Scuber charges a flat fare for a distance over 2000 feet and under 2500 feet. Finally Scuber does not allow any rides over 2500 feet - the function returns 'cannot travel that far' if a ride over 2500 feet is requested.

View Functions Lab on Learn.co and start learning to code for free.

js-basics-functions-lab-web-103017's People

Contributors

gj avatar jeffkatzy avatar alexgriff avatar aviflombaum avatar georgelgore avatar joannasese 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.