Return, what it does?


it’s been two days now in front of this exercise, and i still don’t get what RETURN does.

let orderCount = 0;

const takeOrder = (topping, crustType) => {
  console.log('Order: ' + crustType + ' pizza topped with ' + topping);
  orderCount += 1 ;

**let getSubTotal = (itemCount) => {**
**  return itemCount * 7.5;**  

takeOrder('mushroom', 'thin crust');
takeOrder('spinach', 'whole wheat');
takeOrder('pepperoni', 'brooklyn style');


if return is present, we have a numerical result, if it not present, we have “undefined”.
But why, what it does? Why not writing something like
subTotal = orderCount * 7.5

Many thanks


return hands something back, which you can then log to the console

that is a terrible idea, a lot of the reasons are listed here:

but might be complex to understand when new to programming


I see, thank you very much for the reply and the link.
But i still don’t get it, Klingon is more understandable to me!
I already restarted the function module, I am going to restart the js course, hopefully it’ll be of some help.
Bye :slightly_smiling_face:


what do you not yet understand? return?


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