Short term memory


#1


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


#2

i get back an error message of Invalid shorthand property initializer not sure what is wrong


#3

Invalid return statement. We don't need to return anything. The total variable gets accumulated, and that's it.

this.total += itemCost || 0

#4

so your saying it should just be

add: function (itemCost) {
this.total += itemCost;
}

???

that returns the same response but maybe there is something im missing out of your answer


#5

that wasnt the only error but thanks for the help ive figured out my issue


#6

You'll find that I generally don't jump right in and find all the errors. Finding one is enough to get the ball rolling toward a solution. It's good that you found the solution.


#7

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