4/7 Won't Work


#1

Hi, this is my code for the cash register and it keeps returning 0 or just saying that my 'quantity' doesn't seem to work. No idea what I'm doing wrong, I've looked through the code like 10 times.

var cashRegister = {
total:0,
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);


#2

For the 'switch' function arguments, you need to take out the quantity:

Becomes:

I have tested this code out(with the 1 argument in the switch statemen) and it works just fine! :wink:


#3

Thanks a ton! @krazykodekat