3/7 "missing before statement"


#1

I have posted this one several times, but I still have yet to get the right answer. It keeps throwing a syntax error. Please help! I've been stuck for days!

var cashRegister = {
total: 0,
add: function (itemCost) {
this.total = itemCost + this.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);
            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

Oh man! That's one of the hardest things to debug right there! You put a colon instead of a semi colon in one of the cashRegister scans. :smiley: That would be a pretty hard one to debug.


#3

Could you finish this one?
I´m stuck on it also, and can´t find a way out...


#4

@thiagosixel,
@adrynochrome,

nice to know

You could test in labs repl.it
choose Javascript
You will get a split-screen
In the left-hand-side you paste-in your code
click on the Run button.
The right-hand-side is the console

references

www.crockford.com --> for most respected guide-line in Javascript
like coding convention
www.crockford.com
http://javascript.crockford.com/code.html
http://javascript.crockford.com/survey.html


#5

I did that, there´s something wrong on the scan part, i gues, that´s where the red dot with a X appears...

the response on the console is "SyntaxError: Unexpected identifier"


#6

@thiagosixel,
and that was exactly what @ragezapper was writing about....
[quote]
Oh man! That's one of the hardest things to debug right there! You put a colon instead of a semi colon in one of the cashRegister scans.
[end-quote]

So you have to change the colon-: into a semi-colon-;

PS.
Did you hover over the X, you will get an indication of what the problem is about....


#7

Problem solved! thanks a lot everybody!!!
Thanks Leonard, all make sense now...


#8

can you share your code..


#9

Did you make sure you have a comma after the add function?

add: function (itemCost)
{
this.total = itemCost + this.total;
}, <------ notice the comma here, it won't work without it.


#10

@pywhiz84909 is absolute right. I've just racked my brain with this for ages before realising that sneaky sneaky comma was missing.

JSLint managed to pick it out for me. It's been so useful on the more difficult of challenges on this course.

(just assume: "in development"
and tolerate: "this" and "messy white space")


#11

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

};

whats wrong i dont get it


#12

please help ghelpppp


#13

LOL I found the error


#14