3. Short-Term Memory - Unexpected Identifier


#1

Hello!

I'm receiving an "unexpected identifier" error for exercise 3. I took a look at some of the other topics for this specific exercise, and couldn't find what was wrong with my code. Any help would be greatly appreciated!

Thank you,

-Hassan


Exercise 3 Link

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

Take a look at this part;

    add: function (itemCost) {
        this.total += itemCost;
    } // add a comma here
    
    scan: function (item) {
        switch (item) {

You need a comma there, to separate the functions. Remember, every item in an object needs to be separated by a comma;

var myObj = {
    item1: value,
    item2: value2,
    item3: value3,
}

#3

Success!

Thanks so much for your help Chris.

-Hassan


#4

No problem. Happy to help :smiley:


#5