Bleep Bleep Help


#1

Hey, I really can't figure out where I'm going wrong here. Can someone tell me where I'm messing this up? It says "SyntaxError: missing : after property id".


var cashRegister = {
    total:0,
    this.lastTransactionAmount = itemCost
    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;
    },
    voidLastTransaction: function() {
     return this.total -= lastTransactionAMount 
     this.lastTransactionAmount = 0;
    }
    
    
};

cashRegister.scan('eggs',1);
cashRegister.scan('milk',1);
cashRegister.scan('magazine',1);
cashRegister.scan('chocolate',4);
cashRegister.voidLastTransaction();
cashRegister.scan('chocolate',3);


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


#2

Error messages usually come with line numbers for what was being executed at the time of the error, that's left out in the js lessons for whatever horrible reason, can't imagine there's a good one.

Here's what it looks like if I run your code on my machine with nodejs:

$ node potato654.js 
/tmp/js/potato654.js:3
    this.lastTransactionAmount = itemCost
        ^
SyntaxError: Unexpected token .

Your browser is also able to run js code, I know firefox has a scratchpad (shift f4), chrome might be a bit tricker
or install nodejs
or run it in some online interpreter

And those should all give you more verbose error messages if you should need it

In this case nodjs actually found a different problem first and reported that instead.


#3

Thanks for the resource to check out. When I looked at the error message on Firefox's scratchpad it gave me an error of "Exception: SyntaxError: missing : after property id @Scratchpad/1:3" Honestly, I'm not really sure of what's wrong in line 3 though. I've added a colon to that line in all of the places that it could matter and it's still not working. Wat do? :sweat:


#4

Compare to the line above/below, what do they do with colons?


#5

Alright I figured it out, thanks for the help. :relieved:


#6

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