3/7 What's wrong in my code?


#1
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;
        
        //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.add("eggs");
cashRegister.add("eggs");
cashRegister.add("magazines");
cashRegister.add("magazines");
cashRegister.add("magazines");
//Show the total bill
console.log("Your bill is "+cashRegister.total);

Please help!

This code print: Your bill is 0eggseggsmagazinesmagazinesmagazines


#2

you are using the add method at the bottom where it tells you to scan. Also, the "magazines" should just be "magazine"


#3

It's come up several times about the meaning of return true; and I have several times given lengthy postulates on the subject. The real truth, I am come to believe, is that the author wanted a way to see who copy/pasted from the first lesson into later lessons. It's only too obvious to anyone who is really watching these threads. We can tell copied from original, by now.

Just tossing this into the fray.