Please help to read my code? 5/7 Bleep Bleep

var cashRegister = {
    //Dont forget to add your property
    add: function(itemCost) { +=  itemCost;
        this.lastTransactionAmount = 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;
        return true;
    //Add the voidLastTransaction Method here
    voidlastTransaction: function() { -= this.lastTransactionAmount;
        this.lastTransactionAmount = 0;


//Void the last transaction and then add 3 instead

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

It always says "Oops, try again, false".


Hi, thanks for the post. i was able to solve the problem with your help. Having said that, i would remove this line from your code in the method “voidLastTransaction”. I’m not sure why you have it.



You re-initialize the lastTransactionAmount to =zero= AFTER you have used the voidLastTransaction
as you do not want this Method to be used more than once.



Thanks for your kind reply. I’ve actually tried removing that line “this.lastTransactionAmount = 0;” but the result is still the same.

The reason for this is exactly as @leonhard_wettengmx_n said. To minus the lastTransactionAmount twice is meaningless and it would be safer to reset it after you called this method.


Hi all,

I find the cause.

The name of the method should be “voidLastTransaction” instead of “voidlastTransaction”. The L should be in capital.