4/7 Works the way it should but receives an Error


#1

The error reads

: It doesn't seem like your 'quantity' actually works!

This my solution...

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.998 * 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);


#3

The problem is on this line

case "magazine": this.add(4.998* quantity); break;

Codeacademy is testing for a number with only two decimal places and since you have this price 4.998 with three decimal places JavaScript will automatically round the result to three decimal places to make it work you have to do this

case "magazine": this.add(4.99* quantity); break;

#4

Did the trick! Much appreciated @rydan.