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

What's wrong with my syntax?

I'm taking on of the code challenges for javascript. I found a previous answer to my problem but still having problems. What am I doing wrong. Me and javascript don't get along.

script.js
function max(a,b) {  
  if (a > b) {
    return("a is greater');
  } else {
    return("b is greater');     
  }
}

max(2,6);           
Cheo R
Cheo R
37,150 Points
return("a is greater');

return("b is greater');     

You're staring strings with double quotes and ending them with single quotes. Simple fix. Happy coding (I don't get along with JavaScript either).

1 Answer

Vance Rivera
Vance Rivera
18,322 Points

You and javascript will eventually get along. You just got to believe. So in this code what are you trying to accomplish? You can do either two things here either return a string with the results of the function or display a message in the console. Right now you are not doing anything with your code because the syntax is off.

//option 1
function max(a,b) {  
  if (a > b) {
    return "a is greater";
  } else {
    return "b is greater";     
  }
}

var myMaxString  = max(2,6);

//option 2    

function max2(a,b) {  
  if (a > b) {
    console.log("a is greater");
  } else {
    console.log("b is greater");     
  }
}

max2(2,6);