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

where am i getting it wrong

create a new function named max which accepts two numbers as arguments

function (max)
function myFunction(p1, p2) {
    return p1 * p2;         

2 Answers

11,034 Points

Hello Hilary, You haven't posted your question fully. I have to go back to that section and checked for you. This is one of the possible solutions. CODE CHALLENGE 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.

[Moderator redacted]


Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

SHASHIDAR MANDALOZU I took the liberty of changing your comment to an answer. Besides keeping the forums tidy by marking the answer as answered, it allows for voting on your answer. Also, note that the challenge is linked at the top of this question under the "View Challenge" button. Thanks for helping out in the Community! :sparkles:

Michael Hulet
Michael Hulet
47,912 Points

Also, for future reference, it's frowned upon in the Community to post answers to code challenge that just work without explaining why it works. Accordingly, I've redacted the code in your answer. If you'd like, feel free to re-post the code in your answer, but be sure to explain why it works and fixes OP's problem. Also, be sure to modify it so it can't be copy/pasted into a challenge and pass. Thanks for helping out in the Community!

11,034 Points

Thank you Jennifer Nordell. I am a newbie to Treehouse (My second day to be specific). It's great so far. Learning how to post Questions and answers.