Skip to content

Instantly share code, notes, and snippets.

@mklabs
Created November 1, 2010 18:06
Show Gist options
  • Select an option

  • Save mklabs/658624 to your computer and use it in GitHub Desktop.

Select an option

Save mklabs/658624 to your computer and use it in GitHub Desktop.
function calculateTotal(baseTotal, tip, tax, fee) {
// convert the tip to a number using base 10;
// allow for a NaN result from parseFloat
tip = parseFloat(tip) || 0;
// don't allow a negative tip
if (tip < 0) { tip = 0; }
return baseTotal + tip + tax + fee;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment