Created
February 2, 2012 01:41
-
-
Save kevinmeziere/1720828 to your computer and use it in GitHub Desktop.
Tom Gould
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var people =[{ | |
firstName: 'Tom', | |
lastName: 'Gould', | |
cash : 55 | |
}, | |
{ | |
firstName: 'Nadine', | |
lastName: 'Sigillo', | |
cash: 100 | |
}]; | |
var i = 0; | |
while (i <= people.length) | |
{switch(people){case people[0]: | |
people[0].shoppingCart = { | |
dougnuts: 12, | |
beer: 24, | |
cigs: 1 | |
}; | |
break; | |
case people[1]: | |
people[1].shoppingCart = { | |
beer: 8, | |
cigs: 1 | |
}; | |
break; | |
var storeInventory = { | |
dougnuts: 100, | |
beer: 100, | |
cigs: 100, | |
candy: 100 | |
}; | |
var storePrices = { | |
dougnuts: 0.5, | |
beer: 8, | |
cigs: 12, | |
candy: 1}; | |
function checkOut(customer, customerShoppingCart) | |
{var total = 0;customer.posessions = {}; | |
if(customerShoppingCart.dougnuts > 0) | |
{total += customerShoppingCart.dougnuts * storePrices.dougnuts; | |
transferGoods(customer, customerShoppingCart, 'dougnuts'); | |
} | |
if(customerShoppingCart.beer > 0) | |
{total += customerShoppingCart.beer * storePrices.beer; | |
transferGoods(customer, customerShoppingCart, 'beer'); | |
} | |
if(customerShoppingCart.cigs > 0) | |
{total += customerShoppingCart.cigs * storePrices.cigs; | |
transferGoods(customer, customerShoppingCart, 'cigs'); | |
} | |
if(customerShoppingCart.candy > 0) | |
{total += customerShoppingCart.candy * storePrices.candy; | |
transferGoods(customer, customerShoppingCart, 'candy'); | |
} | |
customer.cash = customer.cash - total; | |
} | |
function transferGoods(customer, customerShoppingCart, item){storeInventory[item] = | |
storeInventory[item] - customerShoppingCart[item]; | |
customer.posessions[item] = customerShoppingCart[item];customerShoppingCart[item] = 0; | |
} | |
console.log("Going to checkout");var y = 0;while (y <= people.length) | |
{checkOut(people, people[y].shoppingCart);y++;} | |
console.log("Checked Out"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment