16. building a Cash Register - Unexpected identifier


#1




Hey guys!
can you help me, telling me why this code wont run??

SyntaxError: Unexpected identifier


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

I figured it out.

add: function(itemCost){
this.total += itemCost;
} , <--- the comma :smiley:


#3

You're missing a comma at the end of the braces here as you list the members of the variable.

You should now get an output that says:

Your bill is 16.93

This should resolve. Hope this helps! :smile:


#4

yeah the same thing i realized! just gotta learn how to read! haha :stuck_out_tongue:


#5

Wow! This was driving me crazy. Wouldn't have guessed that a little comma would do the trick. Thanks!!! :slight_smile: