5/7 Get 8.55 but can't proceed?


#1

Not sure what I'm doing wrong? I get the right output - 8.55, but also an error message saying "Oops. Try again. False.) Any help appreciated!

var lastTransactionAmount = 0;
var cashRegister = {
total: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);
console.log("Your bill is "+cashRegister.total);
console.log("last transaction value: "+lastTransactionAmount);

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

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


#2

Hi maybe this will help you:

var cashRegister = {
total:0,
lastTransactionAmount: 0, <-------- this is needed!
//Dont forget to add your property
add: function(itemCost) {
this.total += itemCost;
this.lastTransactionAmount = itemCost; <------ you almost got this right.

This is how the Void needs to look like:

voidLastTransaction: function(){
   this.total -= **this.**lastTransactionAmount; <---- this needs to be added.

hoop it helps.


#3

Same problem. Got 8.55. But Oops, try again. False.


#4

you defined an object.
var lastTransactionAmount = 0:

You should add it as a property
lastTransactionAmount = 0,


#5

I had the same problem and I found out that I didn't write voidLastTransaction, as requested, but voidLastTransactionAmount. The code works, obviously, but the exercise isn't right. So check if you wrote everything exactly as requested, or it wouldn't work.

For example, I can see that you wrote:

but the code that will pass is:

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

It's the same for the code, but not for the exercise.


#6

did you have a solution about it?


#7

This function works

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


#8

Thank you, this helped me solve the course at last!