3/7 Syntax error


#1

hi guys

i keep getting an error saying my syntax is wrong cause i'm missing a '{' sign.

here's my code:
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;
}

};

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

can someone please help me?


#2

I see only one syntax problem, in this line:

add: function(itemCost) = {

You have to delete = operator. I think it's just a typo, but if you need explanation why this syntax is wrong just let me know :smile:


#3

Thank you very much, yeah indeed i understand!


#4

You're very welcome :smile:


#7

honestly i dont understand ur syntax please explain to me? Thanks in advance


#8

hi sorry i didn't get back to you sooner.
for hte function() = {
after function you don't put =

but for the function itself, you have to add the itemcost to the total and that is most easily done with +=

did that help or was it a different part you didn't understand?