4/7 what am i doing wrong


#1

var cashRegister = {
total:0,
add: function(itemCost){
this.total += itemCost;
},
scan: function(item, quantity) {
switch (item) {
case "eggs": this.add(0.98 * quantity); break;
case "milk": this.add(1.29 * quantity); break;
case "magazine": this.add(4.99 * quantity); break;
case "chocolate": this.add(0.45 * quantity); break;
}
}
};

// scan each item 4 times

cashRegister.scan("eggs", 4);
cashRegister.scan("magazine", 4);
cashRegister.scan("milk", 4);
cashRegister.scan("chocolate", 4)

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

Oops, try again. It doesn't seem like your 'quantity' actually works!


#2

there is a space between your comma and quanity


#3

it still does not work


#4

Is the wrong order(and missing a ; at the last line):

cashRegister.scan("eggs", 4);
cashRegister.scan("magazine", 4);
cashRegister.scan("milk", 4);
cashRegister.scan("chocolate", 4)

This should work:

cashRegister.scan("eggs", 4);
cashRegister.scan("milk", 4);
cashRegister.scan("magazine", 4);
cashRegister.scan("chocolate", 4);


#5

I thing the right code is just change milk from 1.29, to 1.23 and it works to me.

var cashRegister = {
total:0,
add: function ( itemCost){
this.total += itemCost;
},
scan: function ( item, quantity) {
switch (item) {
case "eggs": this.add(0.98 * quantity); break;
case "milk": this.add(1.23 * quantity); break;
case "magazine": this.add(4.99 * quantity); break;
case "chocolate": this.add(0.45 * quantity); break;
}
}
};

// scan each item 4 times
cashRegister.scan("eggs", 4);
cashRegister.scan("milk", 4);
cashRegister.scan("magazine", 4);
cashRegister.scan("chocolate", 4);

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