Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

script.js
function (max)
function myFunction(p1, p2) {
    return p1 * p2;         
}
myFunction(2,4);

2 Answers

shashi7
shashi7
11,032 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]

Best

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
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,869 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!

shashi7
shashi7
11,032 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.