Skip to content

Instantly share code, notes, and snippets.

@Jared-Prime
Created April 12, 2012 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Jared-Prime/2371224 to your computer and use it in GitHub Desktop.
Save Jared-Prime/2371224 to your computer and use it in GitHub Desktop.
Taxi Fare - basic functions in JavaScript
// solution to Codeacademy.com project, "Taxi Fare"
// fare based upon miles traveled and the hour of the day
var taxiFare = function (milesTraveled, pickupTime) {
var baseFare = 2.50;
var costPerMile = 2.00;
var nightSurcharge = 0.50; // 8pm to 6am, every night
var cost = baseFare + (costPerMile * milesTraveled);
// add the nightSurcharge from 8pm to 6am
if (pickupTime >= 20 || pickupTime < 6) {
cost += nightSurcharge;
}
return cost;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment