FAQ: Functions - Helper Functions

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

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

Web Development

Introduction To JavaScript

FAQs on the exercise Helper Functions

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

Ask or answer a question about this exercise by clicking reply (reply) below!

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

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

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!

8 posts were split to a new topic: How are the functions connected and where does “number” come from?

4 posts were split to a new topic: What is the difference between var and const?

2 posts were split to a new topic: Why do I get undefined?

3 posts were split to a new topic: Is this an example of a helper function?

Why on earth would we not just use something like:

function converter(number){
console.log(number * 9/5 + 32);

}
converter(15);

Why would we expand this code into more functions than need to be written?
Thanks

1 Like

Hello, @code0542734588! Welcome to the forum.
While this simplistic example may not be very practical, it does show how to use a helper function. If you had several functions that all needed to perform a similar mathematical calculation, and then each function additionally performed its own unique operations with the returned value, this type of helper function becomes very useful to “DRY” your code.

Hey guys I am currently reading the "Helper functions in the introduction to javascript course and just confused.

The part that is confusing me is the return command. Below is the current code that I’m looking at

function multiplyByNineFifths(number) {
return number * (9/5);
};

function getFahrenheit(celsius) {
return multiplyByNineFifths(celsius) + 32;
};

getFahrenheit(15); // Returns 59

In the function multiplyByNineFifths(number), where is the return number * (9/5); that value to?

to the caller, which is here:

multiplyByNineFifths(celsius) 

Still don’t get it >.> ugh. How is multiplyByNineFifths(celsius) getting celsius as a param in the first place?

here:

getFahrenheit(celsius)

you define (name) a function with a parameter named celsius.

then here:

multiplyByNineFifths(celsius)

you call the multiplyByNineFifths function with argument (celsius), which is the parameter of getFahrenheit function

so a function can call a different function with its parameter as argument for the different function.

3 Likes

Alright that makes sense now. But the returned property. Does it return the value to the function that has the parameter?

a function call will execute a function

at the end of a function, return can hand back data to the caller (the function call)

1 Like

Thank you so much. This has helped me a lot

Hi this is about ‘helper functions’ in ‘introduction to javascript’ here In the exercise it
asks to create a helper function to find the total cost of monitors. However at the end it makes the user define the a const variable totalCost and then log it to make sure that it works. I was however wondering why it asks to define a variable and why not just print console.log(costOfMonitors (5,4));

function monitorCount(rows, columns) {
return rows * columns;
}
function costOfMonitors(rows, columns) {return monitorCount(rows,columns) * 200;
}
const totalCost = costOfMonitors(5,4);
console.log(totalCost);

3 Likes

This is all very fine and good if we just wish to confirm the functions work, but what if we wish to use the return value in further computations? A variable is way we can do that.

Of course this makes sense now. Thank you so much.

1 Like

This exercise talks about using helper functions as a way to clean up functions or to break down large logical tasks into smaller manageable tasks. There’s no question that helper functions make the code more readable but out of idle curiosity: is the separation of functions into helper strictly more efficient from a writing perspective or also from a computing perspective? Or would a computer run a large logical task more efficiently if it was a single function? I know the difference is undoubtedly negligible in terms of how fast we perceive it to be running, but I’m just curious.

Helper functions serve single purpose utility, but as standalone objects they can be shared with the rest of the program or included in a module that can be shared with many programs.

Hello guys , I just got a question …how do we solve if helper function has one parameter while the one we invoke (function) has two parameters?