4. I have to scan it more than once


#1



https://www.codecademy.com/courses/close-the-super-makert/0/4?curriculum_id=506324b3a7dffd00020bf661


Why the heck doesn't this work?


var cashRegister = {
    total:0,
    add: function(itemCost){
        this.total += itemCost;
    },
    scan: function(item,num) {
        switch (item) {
        case "eggs": this.add(0.98*num); break;
        case "milk": this.add(1.23*num); break;
        case "magazine": this.add(4.99*num); break;
        case "chocolate": this.add(0.45*num); break;
        }
    }
};

// scan each item 4 times
cashRegister.scan("eggs",4);
cashRegister.scan("milk",4);
cashRegister.scan("magazine",4);
cashRegister.scan("eggs",4);

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


#2

@lloydert,
You are receiving
Oops, try again. Did you scan four of each item?

Have a clos look at

cashRegister.scan("eggs",4);

where is your chocolate ??

#3

Lol ah man it's always the stupid mistakes that trip me up. Can't believe I didn't see that. Thanks!


#4

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("milk",4);
cashRegister.scan("magazine",4);
cashRegister.scan("chocolate",4);

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