4. I Have to Scan It More Than Once?


I cannot find any errors at all. I think it might be connected to the "quantity" in some way since the error message tells about it. But I cannot figure it out. Can anyone find the error in my code and why is it wrong?


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

var cashRegister = {
    add: function(itemCost){
        this.total += itemCost;
    scan: function(item, quantity) {
        switch (item, quantity) {
        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);


Hi this line

switch (item, quantity)

just remove , quantity

I have to scan it more than once?

Ah yes, of course! Thank you


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.