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

tomd
tomd
16,701 Points

Create a max() fuction challeng? Im so stuck. Please help.

I completed part one, but part two makes no sense to me whatsoever.

It says: Beneath the max function you just created, call it with two numbers and display the results in an alert dialog. Pass the result of the function to the alert method.

I wrote this

function max(number1, number2) { if ( number1 > number2) { return number1; } else { return number2; }

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

script.js
function max(number1, number2) {
  if ( number1 > number2) {
    return number1;
  } else {
    return number2;
  }

alert(max(10, 20));

2 Answers

Steven Parker
Steven Parker
231,236 Points

Looks good :+1: ... except that the final close brace to end the function is missing.

tomd
tomd
16,701 Points

Thank you, i have been sitting here for about an hour.... my blood pressure is so high now lol.

This second task is really hard. I don't know what to do. HELP!

Steven Parker
Steven Parker
231,236 Points

You should always start a fresh question instead of asking one as an "answer".

But here's some hints:

  • don't change the function
  • call "alert" after (outside) of the function
  • as the argument to "alert", call your "max" function
  • pick any two numbers to use as arguments in your call to "max"