Return, what it does?


#1

Hello,
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');
console.log(getSubTotal(orderCount));

console.log(orderCount);

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


#2

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:

http://wiki.c2.com/?GlobalVariablesAreBad

but might be complex to understand when new to programming


#3

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:


#4

what do you not yet understand? return?


#5

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