Skip to content

Instantly share code, notes, and snippets.

@kf4x
Created April 27, 2012 23:49
Show Gist options
  • Save kf4x/2514363 to your computer and use it in GitHub Desktop.
Save kf4x/2514363 to your computer and use it in GitHub Desktop.
JavaScript Exam 3 working with arrays. -JavaScript-
function CalculatePrices (enteredNumbers){
var apples = "Number of apples " + (enteredNumbers[0]); // get the number of apples
var oranges = "Number of Oranges " + (enteredNumbers[1]);
var bananas = "Number of Bananas " + (enteredNumbers[2]);
var peaches = "Number of Peaches " + (enteredNumbers[3]);
function calculate (numFruits,fruitType) {
var fruitPrices = [1.49, 0.99, 0.59, 1.89];
return numFruits * fruitPrices[fruitType];
}
var total = calculate(enteredNumbers[0],0) + calculate(enteredNumbers[1],1) + calculate(enteredNumbers[2],2) + calculate(enteredNumbers[3],3); //subtotal
var tax = total * 0.07; //tax
var totaltotal = tax + total; //subtotal + tax
return '<br>' + apples + '<br>' + oranges + '<br>' + bananas + '<br>' + peaches + '<br>' + ' The subtotal for your order is '+ total.toFixed(2) + ' your tax is ' + tax.toFixed(2) +'<br>' + 'for a grand total of '+ totaltotal.toFixed(2); //return the message when the fn is called
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment