3. Short-Term Memeory


#1

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

Hello, I'm stuck in this activity.
Well, I have my code underneath, but when I run the code, it says "There was a problem with your syntax.", and on the console window, there was an error message "SyntaxError: Unexpected token :". I don't know why my code doesn't work. Can someone help me please? Thank you!

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

Does it indicate what line it is on?


#3

take a look here:

case "eggs":

and here:

case: "magazine":

in one case (sorry, to tempting) you do it correctly, a single colon at the end

in the other case, you use two colons, there shouldn't be a colon after case keyword

@825orion, no it doesn't. To get this result, you will need to use a JS debugger


#4

True pun-master here.

Thanks for the sharp eyes.


#5

Yes, it worked! Why couldn't I figure out this problem? Thank you very much, @stetim94 and @825orion


#6

because this kind of typo's are really difficult to find. Yes, once you see it: oh, easy. But the problem is finding it.


#8

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