What the heck is Wrong? 5. Bleep Bleep


It keeps saying SyntaxError: Unexpected identifier but my code seems to be perfect

I am probably wrong but I am terrible at debugging

    //Dont forget to add your property
    var add = function(itemCost) {
        this.total +=  itemCost;
        this.lastTransactionAmount = itemCost;
    lastTransactionAmount: 0,
    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;
    //Add the voidLastTransaction Method here
    voidLastTransaction: function() {
        this.total -= this.lastTransactionAmount;


//Void the last transaction and then add 3 instead

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


Two contradictory statements. How can we know if our code is perfect if we are not able to debug code (meaning we don't recognize our mistakes)?

Seems this is not being followed. There should be an entry above for 'chocolate', 4. Then the transaction is voided, and a new scan of 'chocolate', 3 is to be inserted. Is that the gist of this exercise?


I know, but it says it is a syntax error, it puzzles me, I am looking to learn what is wrong with it.


If it says, "unexpected identifier" what should you be looking for?

Answer: identifiers.

There is some missing code at the beginning. We don't see the cashRegister object definition.

var cashRegister = {


Since this is (supposed to be) inside the object literal, it should be a property, not an assignment statement, and no var. It is part of the defined variable, cashRegister.

add: function (itemCost) {