2/7. Manually Add It Up?


I might of misread something, but I don't understand how to call the method four times. Can someone help me by giving the correct code? Here is my code now..

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

//call the add method for our items

//Show the total bill
console.log('Your bill is '+cashRegister.total);

Would I have to call that multiple times? I'm confused


This is an early lesson that demonstrates what the program will be doing later on, programmatically, rather than manually. For now, though, just call the add() method with four different amounts:


Then log the total:

console.log('Your bill is ' + cashRegister.total);

That's if I am reading this question right. If I am not on base, please post a link so we can check things out for outselves.

Off topic best practice tip:

Let readers see the operators by leaving white space around them.

    a + b
    // rather than

You'll thank yourself later for adopting this practice on all operators.


Oh..Okay. That makes a lot more sense...Thank you!


seemed like an array made more sense.
var x = [prices]
var z = 0;
for (var i = 0; i < x.length; i++){
z += x[i];

then the method is the object.method(z) or is this just more convoluted than necessary?


I was lazy lol..

cashRegister.add(0.98 + 1.23 + 4.99 + 0.45);