JavaScript JavaScript Basics Creating Reusable Code with Functions Create a max() Function

M Angele U. GASANA
M Angele U. GASANA
2,576 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
170,273 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
2,576 Points

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

Steven Parker
Steven Parker
170,273 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!