Building a Cash Register


I don't really understand the purpose of returning a boolean in scan method and why you have an "OR 0" in the add method in this line => [ += (itemCost || 0);]

    add: function(itemCost) { += (itemCost || 0);
        this.lastTransactionAmount = itemCost;
    scan: function (item) {
        switch (item) { 
        case "eggs": 
        case "milk": 
        //Add other 2 items here
        case "magazine":
        case "chocolate":
        return true;


This is not a boolean, but a logical expression. If itemCost is a valid number that can be added to the total, it is the value added, otherwise, zero is added to the total.


Thanks for your reponse, that's what I thought.

Concerning the boolean I was actually referring to the "return true" at the end of the code. Is it a way to tell that the method ran smoothly (without any error) ?


The only reasonable explanation I can come up with is that the author wanted to function to have a return value other than undefined. I've been scratching my head on that one for years.

Somewhere in the old forum archives one might find a post where I explored scan validation that expanded on that. Trying to remember the post so I can search for it.


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