4- SyntaxError: Unexpected token ILLEGAL


#1


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


"Oops, try again. There was a problem with your syntax."
"SyntaxError: Unexpected token ILLEGAL"
No other error messages
I have no idea what I'm doing wrong here, I went through the syntax again and again, messed around with the semicolons after the }s... :sob:


var cashRegister = {
    total:0,
    add: function(itemCost){
        this.total += itemCost;
    },
    scan: function(item, quantity) {
        switch (item) {
        case "eggs": 
            this.add(0.98 * quantity); 
            break;
        case "milk": 
            this.add(1.23 * quantity);
            break;
        case "magazine": 
            this.add(4.99 * quantity); 
            break;
        case "chocolate": 
            this.add(0.45 * quantity); 
            break;
        }
        return true;
    }
};

// scan each item 4 times
cashRegister.scan('eggs', 4);
cashRegister.scan('milk', 4);
cashRegister.scan('magazine', 4);
cashRegister.scan('chocolate', 4);


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


#2

your problem is coming from here

case "milk":
this.add(1.23 * quantity); // here you see quantity) but its actually not.you can see it below.

so remove that. :slight_smile:


#3

I am baffled :hushed:
What is that and how would I remove it?
I tried erasing and retyping, also copy-pasting from above, but still get the same error.


#4

use notepad to see your typing is right or not.just copy the code and paste it in notepad.see the error what i've said.if you still get the same error then paste it here.


#5

I copy-pasted my code into textedit and I don't see anything strange in it. This was after retyping before so maybe there was that error and now it's fixed. Still get the same error message though :frowning:
Thanks for the help.
Here goes the code again:

var cashRegister = {
total:0,
add: function(itemCost){
this.total += itemCost;
},
scan: function(item, quantity) {
switch (item) {
case "eggs":
this.add(0.98 * quantity);
break;
case "milk":
this.add(1.23 * quantity);
break;
case "magazine":
this.add(4.99 * quantity);
break;
case "chocolate":
this.add(0.45 * quantity);
break;
}
return true;
}
};

// scan each item 4 times
cashRegister.scan('eggs', 4);
cashRegister.scan('milk', 4);
cashRegister.scan('magazine', 4);
cashRegister.scan('chocolate', 4);

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


#6

hahaha lol :smiley:
now

see before var same thing :smiley: remove that.and sorry that time i forgot to tell you.


#7

Amazing!

This time it worked. :hushed:

Thank you!


#8

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