Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Create a max() Function

Please TH, tasks should be always more elaborated. I don't understand the task in this instance. Any help appreciated.

Below you will see the task explanation (I'm not grasping it, unfortunately).


Create a new function named max which accepts two numbers as arguments (you can name the arguments, whatever you would like). The function should return the larger of the two numbers.

HINT: You'll need to use a conditional statement to test the 2 parameters to see which is the larger of the two.


What should be done?

Steven Parker
Steven Parker
231,269 Points

It doesn't look like you've written any code yet.

At least please give it a good-faith attempt and then ask for help if you have trouble, and be sure to show your code.

If you don't know how to begin, it might be good to review the videos and be sure to follow along in the workspace.

2 Answers

Huzaifa Sajjad Malik
PLUS
Huzaifa Sajjad Malik
Courses Plus Student 10,823 Points

Mate its pretty simple the task is to create a function which checks which number is greater.Say you have two packs of milk and you have to check which one of them is heavier what would you do?I guess you would compare the both and then decide which one is heavier.Apply this example on the task and you would be able to solve it.Any how i am leaving the function prototype I guess you are confused on how to create a function.

function max(milkPack1,milkPack2)
{
    //compare the two maybe store the result in a variable and then return it or print it out directly
}
Nela Kay
Nela Kay
11,855 Points

I understand this question pretty well. The task seems confusing to me, the description is not well thought out. But thank you for the attempt of explaining what should be done. I guess I get it now a little better...