Can you help point out what is wrong with my code here: The goal is to to compute the total amount spent by a diner party of 3 people, each ordering 2 dishes.
I know there are other ways to do this using 'this' and 'new' in a more oop manner, but I think my approach here is more readable..if I can make it work. The code works fine if each patron only orders 1 dish so there is something wrong with the way I have been trying to access the JS dictionary.
Sorry about the newbie question. Any help is appreciate!
var diners=[
{name:'adam', entree1:'ramen', price1:11.5, entree2: 'miso', price2 : 3},
{name:'bobby', entree1: 'udon', price1 :10.69, entree2: 'gyoza', price2 :4.5},
{name:'carly', entree1: 'teriyaki chicken', price1:12, entree2: 'miso', price2 : 3},
];
var entrees1_total=0;
for (var d in diners){
entrees1_total += diners[d].price1; //total expense of entree1 for all diners
diners[d].tax1 = diners[d].price1*0.082; // method for sales tax
entrees1_total += diners[d].tax1; //total entree1 price including sales tax
}
var entrees2_total=0;
for (var d in diners){
entrees2_total += diners[d].price2;
diners[d].tax2 = diners[d] * price2 * 0.082;
entrees2_total += diners[d].tax2;
}
var total = entree1_total + entree2_total;
var total_bill = total*1.2; //tips
console.log("total is: " + total_bill.toString());
for (var d in diners) {
console.log(diners[d].name + " spends " + (diners[d].price1 + diners[d].tax1)+(diners[d].price2 + diners[d].tax2));
} // print out total spent for each patron