Skip to content

Instantly share code, notes, and snippets.

@pragmaticobjects
Created September 11, 2011 04:32
Show Gist options
  • Select an option

  • Save pragmaticobjects/1209169 to your computer and use it in GitHub Desktop.

Select an option

Save pragmaticobjects/1209169 to your computer and use it in GitHub Desktop.
Switch Case
var calculateTotal = function(item, price) {
var tax= 0.08;
var fee = 10;
var sinTax = 0.02;
switch (item) {
case 'gas':
return price + price*tax + fee;
case 'wine':
return price + price*tax + price*sinTax;
default:
return price + price*tax;
}
};
var total = calculateTotal('wine', 100);
alert(total);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment