3/7 Short Memory , Can someone Explain this?


#1


So, my code Works but I would like to know why in the add:function we end it with a comma( , ) instead of a ( ; ), When would we need to difference between using one or the other and wich case scenarios applies for each, could someone explain this ?

My guess is that we have an extra function in this case the scan:function and thats why, if it was only 1 function lets say add or just scan it would end on ( ; ) but since theres 2 the add one ends on ( , ) I'm probably wrong due to lack of experience , looking forward for an explanation on this !


var cashRegister = {
    total: 0,
    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.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

add() is a method of the cashRegister object, in other words an object property. We separate properties in object literals with a comma.


#3

Thank you ! I got it! even do we assign a function/method it still dosen't stop to be a property well an object property thats why , right ? cause its inside the object cashRegister