Cash register short term memory not working


#1

gives me syntax error

var cashRegister = {
    total: 0,

//insert the add method here
    add: function(itemCost){
        this.total +=itemCost;
    }

    
    scan: function (item) {
        switch (itemCost) { 
        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;
        
        }
    }
};

//Scan 2 eggs and 3 magazines
cashRegister.scan("eggs");
cashRegister.scan("eggs");
cashRegister.scan("magazines");
cashRegister.scan("magazines");
cashRegister.scan("magazines");
//Show the total bill
console.log('Your bill is '+cashRegister.total);

#2

Hi @genius-mark1

What syntax error are you getting?


#3

Hi,
had same problem but found out.

Keep attention what is missing after add method.

Also will be problem here: item is "magazine", but what are you scanning ?


#4

Please, add comma after add method:

 add: function(itemCost){
        this.total +=itemCost;
 } // here should be , after }

Also here:

 scan: function (item) {
        switch (itemCost) { ... } // should be item unstead of itemCost

Method scan takes parameter item not itemCost.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.