Cash register 3/7 :SyntaxError: expected expression, got '}'


#1

var cashRegister = {
total: 0,
//insert the add method here
add : function(itemCost){
this.total+=itemCost,
},

scan: function (item) {
    switch (item) { 
    case "eggs": 
        this.add(0.98); 
        break;

    case "milk": 
        this.add(1.23); 
        break;

    //Add other 2 items here
    case "magazine":
        this.add(4.99)
        break;
    case "chocolate":
        this.add(0.45)
        break;
    }
    return true;
}

};

//Scan 2 eggs and 3 magazines
cashRegister.scan("eggs")
cashRegister.scan("eggs")
cashRegister.scan("magazine")
cashRegister.scan("magazine")
cashRegister.scan("magazine")

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


#2

Hey there @boardsurfer52421! You got two problems buddy!

First: You dont end with a comma, you do it with a semicolon.

Here is the problem spot for the code:

Should be like this:

this.total+=itemCost;

Secondly you placed a comma in a incorrect spot after your bracket

Here is the incorrect spot:

Delete that quote after the bracket and you should be fine! If there are any other problems please reply saying so!


#3

Just saying the like simple problem that @amanuel2 helped me find, all you have to do is change the comma into a semi colon and it works like bingo. :smiley:


#4

thanks a lot :smile:


#5

No problem @boardsurfer52421 Glad to help!!!


#6

Hey can anyone help me ive been staring at this for ages now it says i have a syntax error but cant figure out where

var cashRegister = {
    total: 0,
add: function (itemCost)  {
    this.total += itemCost;
}
    scan: function (item) {
        switch (item) { 
        case "eggs": 
            this.add(0.98); 
            break;
        
        case "milk": 
            this.add(1.23); 
            break;
        
        //Add other 2 items here
        case "magazine":
            this.add(4.99)
            break;
            
            case "chocolate":
                this.add(0.45)
                break;
        
        }
        return true;
    }
};

//Scan 2 eggs and 3 magazines
cashRegister.scan ("eggs")
cashRegister.scan ("eggs")
cashRegister.scan ("magazine")
cashRegister.scan ("magazine")
cashRegister.scan ("magazine")
//Show the total bill
console.log('Your bill is '+cashRegister.total);