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


6,232 Points

Javascript Basics, alert numbers

Not sure what this one needs?

Call the function and display the results in an alert dialog. You can pass the results of a function directly to the alert() method. For example, to display the results of the Math.random() method in an alert dialog you could type this:

function max(num1, num2) { if (num1 > num2) { return num1; } else { return num2; } }

alert(max(num1, num2));

Last question on the course for me to complete Javascript basics woo

You have to create a function and call it.

Remember the syntax of a function:

functionName(parameter1, parameter2, parameter3) { code to be executed }

Just create a random function, let's say:

function random(value1, value2) { return value1 + value2; }

//And call it by using the build in alert(); function


//And you'll get 7 shown in an alert box.

2 Answers

Jeff Jacobson-Swartfager
Jeff Jacobson-Swartfager
15,419 Points

With the previous part of the challenge, you created a max function. Now, you just need to call it in an alert. You will need to pass 2 numbers to your max function.

Francisco Santiago
Francisco Santiago
9,591 Points

If anyone needs this answered I must share my findings due to being stuck on it for a while, see below; ( I found that the only way that it worked for me was closing parentheses which I overlooked, all three must be closed for this to work) hope this helps anyone not picking up on this minor oversight:

alert( Math.random( ) ); function max( num1, num2 ) { if (num1>num2) { return num1; } else { return num2; } } alert( Math.random(max(1, 2)) );