3/7 can't figure it out


#1

var cashRegister = {
total: 0,
//insert the add method here
add: function (itemCost){
this.total + itemCost = total;

},

}

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

and following code will NOT be seen as integral part of the cashRegister object


#4

hmmm.....i deleted that bracket, but it still says "ReferenceError: invalid assignment left-hand side"


#5

should be
this.total = itemCost + this.total;


#6

or this.total += itemCost


#7

Thanks a ton @leonhard_wettengmx_n this.total = itemCost + this.total; this worked for me and Thanks to @c1trusfru1t your answer this.total += itemCost also worked for me I tried both of them :grinning:

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