class Shopping { constructor() { this.items = this.getItems(); this.amountHundred = this.getAmountHundred(); } getItems() { let cartItemsStringed = localStorage.getItem("cart"); let jsonParse = JSON.parse(cartItemsStringed); console.log(jsonParse); return jsonParse; } getAmountHundred() { if (this.amountHundred) { return this.amountHundred; } let amount = 0; console.log(this.items); for (key in this.items) { let itemObj = this.items[key]; amount = itemObj.price * itemObj.qty; } this.amountHundred = amount; return this.amountHundred; } } let ShoppingObj; $(document).ready(function() { ShoppingObj = new Shopping(); })