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

I am stuck on this challenge can someone help me?

I keep getting a syntax error and I am confused

script.js
function max('1','8')
{

}

2 Answers

Gunhoo Yoon
Gunhoo Yoon
5,027 Points

In short, JavaScript does not understand what you mean because when creating function and declaring parameters, parameters should be name rather than value.

Your code translates to something like this.

function max() {
  ? = '1';
  ? = '8'
}

function in general works like this.

function name(arg1, arg2, ...) {
  ...body...
}

What arg1 and arg2 does is it takes value and bind it to name just like variables. To use them inside the function you simply refer to their name like this.

function sayName(name) {
  return name;
}

//console.log() echo values inside parenthesis to your developer console. 
//F12 -> console in most browsers.
console.log(sayName('myName')) //myName

To give you a hint you can start from here.

function max(number1, number2) {
  //Write your code.
}

Let me know if you got it.

Also, if anyone notice any errors teach me since I'm learner here as well.

Devin Scott
Devin Scott
5,710 Points

JavaScript arguments are like variables, so they have to start with text and no quotes. Answer:

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