Building a Cash Register 4/7


#1

Hello my code seems to have passed,however it did not add quantities much less deliver a price total.
I'd like to understand why it passed but also how to truly produce a price with the required qty.
Here's the code I entered:

var cashRegister = {
total:0,
add: function(itemCost){
this.total += itemCost;
},
scan: function(item,quantity){
item= item +=quantity[x];
switch (item,quantity) {
case "eggs"[quantity]: this.add(0.98); break;
case "milk"[quantity]: this.add(1.23); break;
case "magazine"[quantity]: this.add(4.99); break;
case "chocolate"[quantity]: this.add(0.45); 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);


#2

Couple of fixes:

item= item +=quantity[x];

The above line may be removed.

In the scan method, follow this model inside the switch statement:

switch (item) {
    case "eggs": this.add(0.98 * quantity); break;
    // ...
}

Last, the call expressions should follow this pattern:

cashRegister.scan("eggs", 4);

#3

The scans must also be done in the right order or a Codeacademy error will occur.
// scan each item 4 times
cashRegister.scan("eggs",4);
cashRegister.scan("milk",4);
cashRegister.scan("magazine",4);
cashRegister.scan("chocolate",4);


#4

Good catch! Definitely, order matters.