I Have to Scan It More Than Once? View Each Before


#1

Hello everyone!
I've stucked with one additional task the boss would like to have. It's the option to show on the screen the amount of each product, that a customer has bought. So basocally, when he bought 2 magzines it must show 2 * magazines = price (amount), and each must be displayed in a row.
I did my best till now, and i can print this :

3.92
4.92
19.96
1.8
Your bill is 30.6
undefined
0.98
2.46
14.97
1.8

How can I remove the second part after "your bill is.."
Thanks for help


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


#2

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