Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

williamrossi
williamrossi
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

alert(random(4,3));

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

2 Answers

Jeff Jacobson-Swartfager
Jeff Jacobson-Swartfager
15,418 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)) );