2/7 Oops, try again. What's wrong with this code?


#1

Hello everyone,

I have a problem with lesson 2/7 from 16. Building a Cash Register.

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

//call the add method for our items
cashRegister.add(1.99);
cashRegister.add(1.23);
cashRegister.add(4.99);
cashRegister.add(0.45);

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

This is what's getting printed in the console:
Your bill is 8.66 (I added it up manually, and it is correct)

And this is the message I'm getting:
Oops, try again. Have you called the method four items to add each itemCost?

That's exactly what I did right?? I don't understand what's wrong....


#2

you have the wrong amount for the first item. Its not 1.99 for the eggs it should be .98


#3

i feel so stupid now...
thanks though :))


#4

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

//call the add method for our items
var eggs = 0.98;
var milk = 1.23;
var magazine = 4.99;
var chocolate = 0.45;

cashRegister.add(eggs + milk + magazine + chocolate);

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