Building a Cash Register, return true within switch? what is it for?


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/en/courses/close-the-super-makert/0/7?curriculum_id=506324b3a7dffd00020bf661

<In what way does your code behave incorrectly? Include ALL error messages.>
Please, I would like to know why the “switch” within the “scan method” has “return true”. What is this for? Because the code can run without it.

Thank you

```

var cashRegister = {
total:0,
lastTransactionAmount: 0,
add: function(itemCost){
this.total += (itemCost || 0);
this.lastTransactionAmount = 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;
this.lastTransactionAmount = 0;
},
// Create a new method applyStaffDiscount here
applyStaffDiscount: function(employee){
this.total -= employee.discountPercent*this.total/100;}

};

<do not remove the three backticks above>

#2

In this exercise we don’t make use of the statement, so it is rather superfluous. Why the author chose to include it is beyond me. The only real purpose it has served thus far is to continually raise this question.


#3

Too many words for a haiku, but definitely poetic gold.