3. cash register


#1

I am getting an unexpected token ( error. I can't see where it is.
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", "magazine");
//Show the total bill
console.log('Your bill is '+cashRegister.total);


#2

You are forgetting your semicolons after your breaks, it should look like this:

case "magazine": 
        this.add(4.99); 
        break;

#3

I put them in it didn't work.


#4

Try to also add spaces in between each of these so it'll look more like this:

case "magazine":
            this.add(4.99);
            break;

            case "chocolate":
                this.add(0.45);
                break;

And the last problem you are having (that I can see) is what you are scanning at the bottom, you should've scanned 2 eggs and 3 magazines. The following will scan 1 item:

cashRegister.scan("itemName");

You will have to do this with eggs twice and magazines 3 times.


#5

Ah yes! I don't know how I didn't see this earlier but you forgot to close one of your brackets. Here is what you wrote:

add: function(itemCost){
this.total += itemCost;

When it should be like this:

add: function(itemCost) {
        this.total += itemCost
    },

Just add the "}," and add the other things I spotted before and your code should work!


#6

I was getting a syntax error that this helped, what does the comma signify? I don't remember the comma being used in any other lesson beyond separating the properties in literal notation. Is that what the comma was doing in this instance and I just didn't see it?