7. voidLastTransaction


#1

Hi,
See below for code. Why is there the this.lastTransactionAmount = 0;
Doesn't this basically mean the code below is pretty much useless, since when ever we call up the voidLastTranscation function, it will always equals 0 as if the function didn't work?

voidLastTransaction : function(){
        this.total -= this.lastTransactionAmount;
        this.lastTransactionAmount = 0;
    },


#2

@satty10,
With the lastTransactionAmount property
you are keeping track of the last =transaction= done.

If you had 4 chocolate
you would calculate 4*chocolate-price which you then use as itemCost
You increment this.total with the itemCost
and
you assign this itemCost to the lastTransactionAmount property.

Now if you want to =undo= the last-transaction-done
you would call the voidLastTransaction Method....
and you can only call it once.....

To make sure that calling the voidLastTransaction
will have no effect when is called for the 2nd time...
you assign zero to this lastTransactionAmount property