3/7 Short-Term Memory (I forgot)


#1

*/
Dear CodeCademy Community,

I have been taking some courses with you for a while and solve some puzzles on a daily bases after having taking a Back-End Web-Development course and now studying computer science (i.e. C as a programming language) but keep myself up to date and interested in different approaches through CC & Dataquest.io (really cool for Python & Data Science)

Well, I stumbled into a problem here and don't seem to find the SyntaxError: Unexpected Identifier.
Could you help me? Also - (it will probably be solved in the next chapters) - how can I print out multiple items instead of typing duplicates as in the "cashRegister.scan('egg');" twice?

Best,
Con
/*
//_________________________________________________________________________________________

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;
        
        case "magazine":
            this.add(4.99);
            break;
        case "chocolate":
            this.add(0.45)
        }
        return true;
    }
};

//Scan 2 eggs and 3 magazines
cashRegister.scan('egg');
cashRegister.scan('egg');
cashRegister.scan('magazine');
cashRegister.scan('magazine');
cashRegister.scan('magazine');
//Show the total bill
console.log('Your bill is '+cashRegister.total);

#2

*/ UPDATE: I had to add a , after the add function and the switch statement.
And what is the formatting so that code appears in the box as in between the case milk and return true as part of the switch statement?
/*


#3
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()
    {
        this.total -= this.lastTransactionAmount;
    },
    
    
};

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

//Void the last transaction and then add 3 instead
cashRegister.voidLastTransaction();
cashRegister.scan('chocolate', 3)

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

Which Unexpted Token: . is preventing me this time?


#4

I'll just edit your code so we can read it better. remember to use the Preformatted text (Ctrl+Shift+C) button next time :slightly_smiling:


#5

@stinzo after your voidLastTransaction function at it's close brace you have a , since you are not putting any more functions after this one you dont need this , so remove it and it should pass.


#6

Thanks, buddy. Keep it up.
I'll keep it in mind for my next question!