What went wrong?


#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");

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

what went wrong


3/7 SyntaxError: Unexpected Token
#2

@warm_tacos,

An object has one or more properties which are separated by a comma-,
Each property consists of a property-key and it's associated VALUE

Your cashRegister object has 3 properties.
a total property with property-key total and it's associated number VALUE 0
an add property with property-key add and it's associated function VALUE
an scan property with property-key scan and it's associated function VALUE

You have to separate these properties with a comma-,
You used the ,-separator between the total property and the add property.
You forgot the one between the add property and the scan property.

P.S.
When you are defining a function within an object
you call this property a Method.
So you have defined an add Method
and a scan Method in cashRegister object