Bleep Bleep-lost about cashRegister.voidLastTransaction();


#1



The code is right, but I do not understand why after calling cashRegister.voidLastTransaction(); I get the last item subtracted. And why this.lastTransactionAmount = itemCost; ?


Replace this line with your code.


#2

lets start at add:

    add: function(itemCost) {
        this.total +=  itemCost;
        var lastTransactionAmount = itemCost;
    },

you give lastTransactionAmount the value of item cost, so you have a variable which holds the last transaction amount. if you have the last transaction amount you can simply subtract it from total:

VoidLastTransaction: function() {
        this.total = this.total  - this.lastTransactionAmount
    }

in case of a wrongly scanned item.


#3

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