3. short term memory


#1

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

I am not sure what is going on with my code. I get the following error:

Oops, try again. Did you remember to add cases for magazine and chocolate? Are all your prices accurate?

Everything I was supposed to add looks correct.

Thanks,

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

cashRegister.scan("eggs","eggs","magazine","magazine","magazine");

console.log('Your bill is '+cashRegister.total);


#2

Your scan method takes one value at a time.
so you need to call the method several times and pass it values.


#3

Instead of this try using the cashRegister.scan function individually for everything you scan.

cashRegister.scan("eggs"); x 2
cashRegister.scan("magazine"); x 3

This is because there is only on parameter for the scan function.


#4

As always you beat me to it :wink:


#5

Thank you, I also fixed my add function:

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


#6

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