Skip to content

Instantly share code, notes, and snippets.

@macikokoro
Created June 20, 2014 06:00
Show Gist options
  • Save macikokoro/6d7fde92253ca1a4cc20 to your computer and use it in GitHub Desktop.
Save macikokoro/6d7fde92253ca1a4cc20 to your computer and use it in GitHub Desktop.
Function arguments to calculate a taxi ride.
// calculates taxi fare based upon miles traveled
// and the hour of the day in military time (0-23).
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 to the cost if it is after
// 8pm or before 6am
if (pickupTime >= 20 || pickupTime < 6) {
cost += nightSurcharge;
}
return cost;
};
// use taxiFare to set tripCost to the cost of your
// ride covering 5 miles at 2 am in the morning
var tripCost = taxiFare(5, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment