Skip to content

Instantly share code, notes, and snippets.

@sauntimo
Created November 16, 2012 13:22
Show Gist options
  • Save sauntimo/4087322 to your computer and use it in GitHub Desktop.
Save sauntimo/4087322 to your computer and use it in GitHub Desktop.
Calculating Costs
var Declined = false;
if(Notice < 3){
Declined = true;
} else if (Notice <6){
NewSubmission["Notice"] = Notice.toString() + " days - £5 Fast track surcharge";
} else {
NewSubmission["Notice"] = Notice.toString() + " days - No surcharge";
}
// Extract the cost from the description string
var CakeCost = parseInt(NewSubmission["Size"].slice(NewSubmission["Size"].indexOf("£")+1),10);
var DeliveryCost = (NewSubmission["Delivery"].slice(0,8) == "Delivery") ? 3 : 0;
var FastTrackCost = (Notice < 6) ? 5 : 0;
// Add all chargeable elements
var TotalCost = CakeCost + DeliveryCost + FastTrackCost;
// Display as text for humans to read
NewSubmission["Total Cost"] = "£" + TotalCost.toFixed(2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment