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

John Odom
John Odom
4,094 Points

Ahoy Fellow Coders! I continuoslyn get a syntax error, despite multiple attempts. Can anyone spot my stupid mistake?

Still getting the hang of return values in functions... now I'm completely stumped

script.js
/*First Attempt*/

function max (1, 4) {
  if (max>4) {
  return 1;} else {
  return 4;}
}

/*Second attempt*/
function max (1, 4) {
  var x = 3;
  if (max < x) {
    return 1} else {
    return 4} 
}

2 Answers

Dale Severude
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dale Severude
Full Stack JavaScript Techdegree Graduate 71,350 Points

Hi John, First replace all your fixed numbers with variables, second max is the function name don't call it within a function.

function max (x, y) {
  if (x>y) {
  return x;} else {
  return y;}
}
John Odom
John Odom
4,094 Points

Champion! Thank you, Dale