Skip to content

Instantly share code, notes, and snippets.

@kevinmeziere
Created February 3, 2012 22:26
Show Gist options
  • Save kevinmeziere/1733307 to your computer and use it in GitHub Desktop.
Save kevinmeziere/1733307 to your computer and use it in GitHub Desktop.
Tom Gould2
var people = [{
firstName: 'Tom',
lastName: 'Gould',
cash: 55
}, {
firstName: 'Nadine',
lastName: 'Sigillo',
cash: 100
}];
var storeInventory = {
dougnuts: 100,
beer: 100,
cigs: 100,
candy: 100
};
var storePrices = {
dougnuts: 0.5,
beer: 8,
cigs: 12,
candy: 1
};
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;
}
}
*/
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