Skip to content

Instantly share code, notes, and snippets.

@rentpath
Created April 20, 2010 19:18
Show Gist options
  • Save rentpath/372925 to your computer and use it in GitHub Desktop.
Save rentpath/372925 to your computer and use it in GitHub Desktop.
# Given an original price of $5.00
# When I order one my total price should be $5.00
# When I order two my total price should be $8.35
# When I order three my total price should be $11.70
function calculate_price(quantity, orig_price) {
if (quantity == 1) {
price = orig_price * quantity;
} else {
price = orig_price + ((quantity - 1) * orig_price * 67 / 100);
}
return price;
}
console.log(calculate_price(1, 5.00));
console.log(calculate_price(2, 5.00));
console.log(calculate_price(3, 5.00));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment