4/7 I have to Scan more then once?


#1



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


#3

What is this this.num where does it come from? Your cashRegister object doesn't have a num property. Also scan takes 1 argument and you give it 2, so the second is ignored. And finally this is not how switch works, better review it. Switch has one value in its () and compares this value to the values mentioned after the case keywords.