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

Kary Powell
Kary Powell
1,042 Points

Function max (not working) {

I have tried this multiple ways but to no ado. I need help...

script.js
function max(a, b) {
  if (a > b); {
    return a;
    } else {
        return b;
    }
}
max (3, 6);

3 Answers

Steven Parker
Steven Parker
231,275 Points

You're really close! But the "if" statement should not have a semicolon between the conditional expression and the open brace of the code block.

Then for task 2, be sure to include your function call as the argument to an alert function call (call inside a call).

Kary Powell
Kary Powell
1,042 Points

Thanks, guys! That fixed it. I really appreciate the help. It's the little things I haven't solidified yet.

eslam said
PLUS
eslam said
Courses Plus Student 6,734 Points

-first of all remove ; after the if statement your code should look like this

    if (a > b) {

-now you have a function that will return a value but you didn't tell the function to do anything so to print the value of your function to test it out you can use 1 of the 2 methods

console.log(max(3,6));
document.write(max(3,6));