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

M Angele U. GASANA
M Angele U. GASANA
5,500 Points

Use a conditional statement to test 2 parameters

well, I am trying to get this code right but I can tell somethings are missing! I could use some help! thanks

script.js
function max(10,20){

}if { 10>"20" ;
     return 10; 
} else { return 20};

2 Answers

Steven Parker
Steven Parker
231,271 Points

The basic structure looks right, but you have a few syntax issues:

  • parameter names cannot be numbers (or start with a digit)
  • parameters, like variables, should never be enclosed in quotes
  • the conditional clause of an "if" statement should be enclosed in parentheses :point_right: ( )
  • the opening brace of the code block goes after the conditional clause
  • there should be no semicolon between the "if" statement and the code block opening brace
M Angele U. GASANA
M Angele U. GASANA
5,500 Points

thank you, I guess that's what happens when one tries to get some coding done till 3 am!!

Steven Parker
Steven Parker
231,271 Points

M Angele U. GASANA — And you generally don't retain new learning well when tired, either!

Anyway, glad I could help. You can mark a question solved by choosing a "best answer".
And happy coding!