3/7 SyntaxError: missing } after property list


#1

I keep getting a syntax error, and I think I just need a 2nd set of eyes to help me find what I'm missing:

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;
        
        case "magazine":
            this.add(4.99);
            break;
        
        case "chocolate":
            this.add(0.45);
            break;
        //Add other 2 items here
        
        
        }
        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);

Thank you!


#2

Since this is a property, it should end with a comma. LIkewise the closing brace of scan() should not have a semi-colon. Since it is the last property, it needs nothing.


#3

Ah there it is!

thank you so much!


#4

2 posts were split to a new topic: Don't understand what I'm doing wrong


#5

Thank you @mtf. Was wondering, how come in the previous exercise (2/7), a semi-colon could work? Here is the first part of my code for exercise 2/7 :

var cashRegister = {
total:0,
add: function(itemCost){
this.total += itemCost;
}
};
//followed by scan method...and it worked when I submitted.


#6

Was there any compiler error in the console? That's where we should always look, before considering what the SCT error reads, or whether the SCT is lax and letting a poorly executed exercise pass to the next lesson. The SCT is written by one human, the lesson author. It cannot possibly cover all the bases, and is generally quite narrow in focus.

scan and add are properties of the cashRegister object, and as such must be separated by commas. A semi-colon should throw a syntax error.


#7

Instead semi-colon:

should be comma:

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

And it works :slightly_smiling: