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

Joseph Gardin
Joseph Gardin
4,583 Points

creating a max() function HELP

can anybody help me with this task?? i dont even know how to start it besides naming the function....

script.js
function max (two, four) {
  if {

2 Answers

If you don't know how to start, try writing the solution in normal language. So something like.

Calculate max function:

  1. Take a value A and a value B
  2. If A is bigger than B then return A as the answer else return B as the answer

Thats it. Now in JS we can write this as follows:

function max(a, b){
    if( XXXX ){
       return XXXX; 
    }else{
        return XXXX;
   }
}

You can figure out what XXXX should be can't you?

Michael Liendo
Michael Liendo
15,326 Points

You beat me to this one! I deleted my answer since I like your approach of not giving the full answer.

Joseph Gardin
Joseph Gardin
4,583 Points

thanks to both of you guys. it worked.