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

Luis Paulino
PLUS
Luis Paulino
Courses Plus Student 1,779 Points

What is my error?

I know I'm doing something wrong, but I don't know

script.js
function max(5,8){
  if(8>5){
    return 8;
  }

2 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

Hi Luis - You need to use two arguments for your function instead of actual numbers like 8 and 5. You want this function to work for any two numbers passed to it and not just for those two numbers. So in your function definition change the arguments to something like num1 and num2 and modify the if statement accordingly.

An argument in context with functions is the actual value that is passed to the function ( as input) ,when it is called. However parameter refers to the variables that are used in the function declaration/definition to represent those arguments that were send to the function during the function call.

example:

//while defining the function you use parameters or variables
function max(a,b){ 
if(a < b){
return b
}
};

//here you use arguments, or real data when calling the function. 
max(3,7);

I hope this helps.

Kourosh Raeen
Kourosh Raeen
23,733 Points

Hi Jacob - Your code doesn't work correctly when a is greater than b.

Steven Parker
Steven Parker
231,269 Points

You forgot that you still need to return the other value when the test condition is false.

I'm not writing this to give the answer away, Yes, that is correct. The conditional statement reads if a is less than b return b. I did not write an else statement saying else return a. The goal of my post is to explain what are/when to use parameters and arguments. I'm not a huge fan of giving the answer away, but more interested in helping with what the root issue of the question is, in this case its parameters and arguments. I do apologize if I created any confusion.