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

Fabrice Innocent
seal-mask
.a{fill-rule:evenodd;}techdegree
Fabrice Innocent
Full Stack JavaScript Techdegree Student 9,715 Points

Seems like I am missing something

Getting an error message that says my function isn't working because it is not returning the larger number of the two...In my function though I thought I explicitly have it returning the higher value which is the "weight" variable...What am I doing wrong?

script.js
function max(weight, height) {
  var weight = 10;
  var height = 5;
    if (weight > height) {
    return weight;
  } else {
    return height;
  }
}

1 Answer

Hi Fabrice,

the var declarations are not needed inside the functions.

You define the arguments when you call the function (outside of the function). Like this for example:

console.log(max(10, 5));

So you just have to delete the variable declarations in the function for the first part of the code challenge.

Happy coding, Nils

PS: You can upvote my post and/or mark as "best answer" (at the bottom of my post) if it helped you. :-)