5. please help


#1

var cashRegister = {
    total:0,
    lastTransactionAmount:0,
    //Dont forget to add your property
    add: function(itemCost) {
        this.total +=  itemCost;
        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.total -= lastTransactionAmount;
        }
    
};

cashRegister.scan('eggs',1);
cashRegister.scan('milk',1);
cashRegister.scan('magazine',1);
cashRegister.scan('chocolate',4);

//Void the last transaction and then add 3 instead
cashRegister.voidLastTransaction();
cashRegister.scan('magazine',3);

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

the error i keep getting is false , id ont know what to do i tried everything please help. thanks.

and another questin offtopic, any1 who understand more in javascript: the last transaction was chocolate, 4 times chocolat, if i want to void last transaction and i want to remove only 1 chocolate how i can do this? and 1 last this why is there in the scan method return true; what is that for? thanks for the help


#2

Which error are you getting? The output in the console from the code is

"Your bill is 22.17"


#3

yes this is the bill it prints but still getting opps false


#4

ok i found the mistake, the instruction wanted 3 more chocolate and not 3 more magazine, but i have edit some more questions if some1 can answer me please. thanks!