"i have to scan more than once" help


#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.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:


#2

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.)


#3

https://www.codecademy.com/en/courses/close-the-super-makert/0/4

here it is ^_^


#4

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....


#5

thank you ^_^ it worked perfectly