4. I have to scan it more than once?


Codecademy says my code is correct, however my console output is "Your bill is 0eggsmilkmagazinechocolate". Which makes no sense.

this is my code:

var cashRegister = {
    add: function(itemCost, quantity){
        this.total += itemCost;
    scan: function(item) {
        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.add("eggs", 4);
cashRegister.add("milk", 4);
cashRegister.add("magazine", 4);
cashRegister.add("chocolate", 4);

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

Can someone help me resolve this?


Compare this ...

cashRegister.add("eggs", 4);

... to the add function header. What becomes the value of itemCost?



I feel kinda silly now. Thanks for the help! It gives me the expected output now :smiley:


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