I want to make a comparison of an object literal which looks like so...
receipt.tab = {Cafe Latte: 4.75, Cappucino: 3.85}
The items are added when I call the method addItemAndPrice(item)
as found bellow...
var Receipt = function(){
this.tab = {};
};
Receipt.prototype.addItemAndPrice = function(item){
if (comparisonHere???){
this.tab[item] = this.tab[item] + this.tab[item] = menu.prices[item];
} else {
this.tab[item] = menu.prices[item];
}
};
I want to call the method and if there is already a Cafe Latte
found within the tab then I want to add the value of that item to the corresponding item value.
and create this...
receipt.tab = {Cafe Latte: 9.50, Cappucino: 3.85}
FYI menu
looks like this...
var menu = {
"shopName": "The Coffee Connection",
"address": "123 Lakeside Way",
"phone": "16503600708",
"prices":
{
"Cafe Latte": 4.75,
"Flat White": 4.75,
"Cappucino": 3.85,
"Single Espresso": 2.05,
"Double Espresso": 3.75,
"Americano": 3.75,
"Cortado": 4.55,
"Tea": 3.65,
"Choc Mudcake": 6.40,
"Choc Mousse": 8.20,
"Affogato": 14.80,
"Tiramisu": 11.40,
"Blueberry Muffin": 4.05,
"Chocolate Chip Muffin": 4.05,
"Muffin Of The Day": 4.55
}
}