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

I am completely lost now, I dont know what it is but I am struggling with JavaScript. I need my hand held I think lol.

I don't know what it is, I have been sitting here for three days trying to figure this stuff out and Im still not getting it. I know Im new to this and it is all basically a completely different language to me. I really could use a step by step walk through, or someone sitting by my side I think. What am I not getting?

script.js
function max(1, 2) {
  var numbers = 1 < 2;
 return max;
}

Challenge Task 1 of 2

Here's a simple challenge: create a function named returnValue() that accepts a single argument, then returns that argument. This isn't a useful function, but we want to make sure you know how to create a function that can accept information when it is called.

3 Answers

Rich Donnellan
Rich Donnellan
25,767 Points

I normally don't like posting solutions, but it might make more sense to break down.

function max(num1, num2) {
  if (num1 > num2) { // first check
    return num1; // will only return num1 IF it's greater than num2
  } else { // if first check returns false
    return num2; // return num2
  }
}

"Real world" application:

max(3, 6); // call max function passing in parameters

function max(3, 6) {
  if (3 > 6) { // false
    return 3; // will not return since check is false
  } else {
    return 6; // will return
  }
}

Follow?

–Rich

yes thank you, I dont know why Im having these issues, but I appreciate you taking the time to walk me through it.

Rich Donnellan
Rich Donnellan
25,767 Points

Sure thing. How about some upvote or best answer love?

Rich Donnellan
Rich Donnellan
25,767 Points

Carl,

I'll try to break it down as simple as possible.

function returnValue(arg) { //create function named returnValue with one argument; arg in this example
  return arg; // returns the argument
}

If we were pass is real values, it may look something like this:

function returnValue(number) {
  return number;
}

returnValue(10); // calling the function will return what is passed (10).

It might help to read up some more on any topics or syntax you are having troubles with. Check out the Mozilla Developer Network (MDN).

Also, use the search function as a lot of your questions may have already been answered!

Good luck!

–Rich

Thank you Rich

I guess I posted the wrong one, I took a screen shot but I am having issues putting it in my comment. I pretty new to the tech world, I though I new basic stuff, but I am going nuts. How do i post the screen shot of what I am doing to continue to get help?

Sorry about that, still somewhat new to all this.