JSFiddle - React, Tailwind, and code Playground

by Alex Azuero

JavaScript

var cashRegister = {
    total:0,
    add: function(itemCost){
        this.total += itemCost;
    }
};

//call the add method for our items
/*var items = ["eggs", "milk","magazine", "chocolate"];
for (var i=0; i < items.length; i++) {
   alert(items[i]);
	//alert(itemCost);
};
*/
var itemsTotal = 0;
var itemsPrices = {
    eggs: 0.98,
    milk: 1.23,
    magazine: 4.99,
    chocolate: 0.45
};

for ( var i in itemsPrices){
	itemsTotal += itemsPrices[i];
};

//alert(itemsTotal);

cashRegister.add(itemsTotal);
//Show the total bill
alert('Your bill is $'+cashRegister.total);