Another problem


#1



https://www.codecademy.com/courses/close-the-super-makert/0/3?curriculum_id=506324b3a7dffd00020bf661#


SyntaxError: Function statements must have a name.
Oops, try again. There was a problem with your syntax.


var cashRegister = {
    total: 0,
//insert the add method here    
    add: function (itemCost) {
        this.total += this.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
scan("eggs");
scan("eggs");
scan("magazine");
scan("magazine");
scan("magazine");
//Show the total bill
console.log('Your bill is '+cashRegister.total);


#2

This method is missing a closing brace, }. There is an extra stray one at the end of the object literal. Move that one up.


#3

@moritz_2209,
and do not forget to separate the properties using a comma-, separator.


#4

thanks guys, but im having errors at the adding the "eggs" and "magazine"s


#5

Hi and here

//Scan 2 eggs and 3 magazines
scan("eggs");
......

you should do it like that

cashRegister.scan("eggs");

Do it to all your scan


#6

var cashRegister = {
total: 0,
//insert the add method here
add: function (itemCost) {
this.total += this.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);

Im going mad over this, no idea whats wrong


#7

    this.total += itemCost

itemCost is the parameter, not a property of the cashRegister object.


#8

what do u suggest i do


#9

Remove this. from itemCost. It is a local variable, only. It does not exist as a property of the object so we can refer to it in object context.


#10

nvm i got it. Thanks!