"i have to scan more than once" help


var cashRegister = {
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("magazine", 4);
cashRegister.scan("milk", 4);
cashRegister.scan("chocolate", 4);

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

where is the problem ? :confused:


This lesson is too early to be using completed (copied) code from a later lesson. What does the lesson actually ask for? (Please post a link to the exact exercise. Thank you.)



here it is ^_^


I stand corrected. It is so helpful to have the lesson right in front of us so this kind rash judgement is avoided. Pardon me.

Your code gives nearly the correct result, but because the order is switched around, the float is affected. Try scanning milk before magazine. The result will be 30.6 instead of 30.600000....


thank you ^_^ it worked perfectly