5/7 I have no idea what's wrong


Whenever I run this code I get "SyntaxError: Expected '}' ". However, I can't find what's wrong. Any help would be appreciated.

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


//Void the last transaction and then add 3 instead
//Show the total bill
console.log('Your bill is '+cashRegister.total);



i have a problem there too but,,,

i wanna say that your lastTransactionAmount is not accurate
coz u made it equal to itemCost

but lastTransactionAmount it should be equal to last scan as it is not always will be one item for last transaction

meaning uit should be item =Cost * quantity
but when i tried that i got: (quantity is not defined )

lets keep trying



itemCost * quantity


i definitely could be wrong
dont rely on my post


Your code has a number of very basic syntax errors. I should'nt have to point that out to you if you have'nt already solved it.
One of the disciplines you should learn as a beginning programmer is to review your code structure and grammer.
Dump it to a simple text editor if you have to, and format the tabs so you can see the structure easily



i did it :smile:

and by the way your error is happening because of

-- lastTransactionAmount: 0 // should end with comma

-- total -= lastTransactionAmount // should be this.total



i got it all for u,,

first: u don`t need this line lastTransactionAmount: 0
second: inside add method type lastTransactionAmount = itemcost; // not this .lastTransactionAmount
third: inside voidLastTransaction method type this.total // not just total

try these corrections and see


the explanation for that is

u were making a property (lastTransactionAmount)
then using it inside another property

rather u should make the (lastTransactionAmount) as a variable inside the add method.

the other mistake about total and this.total is clear i beleive , we refer to a property by giving (this.property)


now ur code will work

i tried it myself


I went about it a completely different way. I hope this helps. :smile_cat:

var cashRegister = {
    add: function(itemCost){
        this.total += itemCost;   
var groceries = 
    {eggs: .98,
    milk: 1.23,
    magazine: 4.99,
    chocolate: .45

//call the add method for our items
for (var x in groceries)

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


But you don't address quantities at all here. Your code just runs through the entire list once. What if we want to add 4 or 5 of an object and then remove some?

For voiding the last transaction amount, all that's needed is to save the initial total in a separate variable before it had the most recent item added.