# FAQ: Functions - return

This community-built FAQ covers the “return” exercise from the lesson “Functions”.

Paths and Courses
This exercise can be found in the following Codecademy content:

## FAQs on the exercise return

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

## Join the Discussion. Help a fellow learner on their journey.

Agree with a comment or answer? Like () to up-vote the contribution!

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

On this exercise, why is the argument used in the getSubTotal function called itemCount? I understand that the orderCount variable ultimately gets passed in, but wouldn’t it have been simplest to just make orderCount the parameter that was used in the getSubTotal function in the first place? It seems like that works fine and is less complicated.

Where simple values are concerned parameters are independent of the argument given.

``````function foo(orderCount) {

}

foo(orderCount)
``````

The orderCount variable in the argument is not the same variable as the one in the parameter, though it looks the same. They are in two different scopes. A parameter of the same name as the argument is said to shadow the global object meaning it is inaccessible from inside the function. What we call the parameter is completely arbitrary. Only the value is passed in, not the reference.

You’ll find that this is not the case with data structures such as arrays and objects. They are never shadowed as only the reference is passed into the function. This will come up in due course. For now, consider that `orderCount` is a number in global scope, and any parameter that takes it will be in function scope using the local name to refer to the value.

This exercise is attempting to give us a feel for how arguments and parameters work together, and how scope difference places variables of the same name in two different universes.

Wow thank you so much! Like you said, “This will come up in due course.” And I will save this email for when that time comes. I just really appreciate this as it’s given me something to chew on as I’m getting more comfortable with this language. Thanks again!

1 Like
``````var orderCount = 0;
function takeOrder(crustType, topping) {
console.log('Order: ' + crustType + ' crust topped ' + topping);
orderCount=orderCount+1;
}
function getSubTotal(itemCount) {
return itemCount * 7.5;}
takeOrder('thin.', 'Sausage');
takeOrder('Chicago Style.', 'Pepperoni');
takeOrder('Brooklyn Style.', 'Ham');
function takeOrder(topping, crustType){
console.log('Order: A '+crustType+' Pizza topped '+topping)}
takeOrder('normal.','Pepperoni')
var numberPizzas=undefined;
``````

Yet step 2 counts me wrong!?!

Why the second `takeOrder` function?

Is that variable even called for? To set a variable to `undefined`, don’t set it, just declare it.

``var numberPizzas;``

oh i saw this in the first exercise so assumed that that would be the way to declare

It’s not wrong, just not necessary. In most instances we can test for truthiness, unless there is a possibility of some other value being there such as, 0 that we need to include as a valid state.

``````console.log(function(){})
``````

What was logged? We will find `undefined` all over the place, without ever having to actually hard code it.

Might we at some time need to verify it with certainty as being the literal, `undefined`? Perhaps, but rarely is that the case in my experience. Single out these edge cases when you see them and inquire whether there is some other way to make the same determination. That way you have two tools in you kit, instead of just one.

Please don’t let me contradict your lessons. Just know that in a brief lesson, it is impossible to explore down every avenue. That is something we will get to in time, and with lots of study, exploration and practice.

var orderCount = 0

function takeOrder(topping, crustType) {
console.log(‘Order:’ + crustType +‘pizza topped with’ + topping);
orderCount === orderCount + 1
}

function getSubTotal (itemCount) {
return itemCount * 7.5;
}

takeOrder(‘bacon’, ‘thin crust’);
takeOrder(‘bacon’, ‘thin crust’)
takeOrder(‘cheese’, ‘thick crust’)

console.log(getSubTotal(orderCount))

this is my Code, it says everything, i get checkmarks but I dont get a result my result is:
Order:thin crustpizza topped withbacon
Order:thin crustpizza topped withbacon
Order:thick crustpizza topped withcheese
0

But I should get the SubTotal

1 Like

When you use `===` you are comparing the values on each side. To assign a value to `orderCount` you only use `=`. `=` is the assignment operator.`===` is a comparison operator. If you tried `console.log(orderCount === orderCount + 1)` you would see what is happening. You are evaluating whether `orderCount` is the same as `orderCount +1`. It isn’t, so `false` would be logged to the console. Happy coding!

Hi,

I have the same issue but my code seems to be correct. Could you please take a look at:

``````var orderCount = 0

function takeOrder(topping, crustType) {
return ('Order: '+ crustType + ' crust pizza '+'topped with ' + topping )
return orderCount = orderCount + 1;
}

function getSubtotal(itemCount){
return itemCount*7.5;
}

console.log(takeOrder('bacon','thin'));
console.log(takeOrder('sausage','cheese'));
console.log(takeOrder('seafood','thick'));
console.log(getSubtotal(orderCount));
``````

The result I am getting is:
Order: thin crust pizza topped with bacon
Order: cheese crust pizza topped with sausage
Order: thick crust pizza topped with seafood
0

My problem is I should be getting subtotal equals to 22.5 but it is zero.

Do you know what is wrong with my code?

Thank you,
Jeff

Hello, @jeffhsu7. Welcome to the forum.
In your code you declare the variable `orderCount` outside of either function, so it can be reached by your code inside the functions. You need to understand what `return` does. `return` sends control back to the line of code that called a function. Your 2nd `return` statement will never be reached. Control is passed back to the caller in the `return` statement preceding it. You don’t want to execute a `return` statement in any function, ever, until the function has completed the tasks you have assigned to it. If you want to increment your `orderCount` variable each time the function is called, do so before `return`ing anything. Hint: you don’t need to `return` the value of `orderCount`. A simple `orderCount++` will suffice

Hi midlindner,

Thank you very much for the reply. Your are super! I have revised my code to remove ‘return’ in front of the orderCount and move orderCount before a return statement starts.

## New code:

var orderCount = 0

function takeOrder(topping, crustType) {
orderCount = orderCount + 1;
return ('Order '+ orderCount + ': ’ + crustType + ’ crust pizza '+'topped with ’ + topping )
}

function getSubtotal(itemCount){
return itemCount*7.5;
}

## console.log(takeOrder(‘bacon’,‘thin’)); console.log(takeOrder(‘sausage’,‘cheese’)); console.log(takeOrder(‘seafood’,‘thick’)); console.log(getSubtotal(orderCount));

Result:
Order 1: thin crust pizza topped with bacon
Order 2: cheese crust pizza topped with sausage
Order 3: thick crust pizza topped with seafood
22.5

Everything is all good now!! Thank you so much!!!

Jeff

1 Like