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 trialAndrea Algiers
1,147 PointsSending out an alert with 2 numbers from my argument...
I dont know what the alert is supposed to look like. I have tried multiply variations and have no clue what im doing wrong. :(
function max(num1, num2){
if (num1 > num2) {
return num1;}
else if (num2 > num1) {
return num2;}
}
alert( max(num1, num2));
3 Answers
Mladen Ignjatovic
13,602 PointsOK. then just :
function max(num1, num2){
if (num1 > num2) {
return(num1);}
else if (num2 > num1) {
return(num2);}
}
alert(max(3,5));
3 and 5 is just for example you can put any numbers when you cal the function.
Mladen Ignjatovic
13,602 PointsHi Andrea,
function max(num1, num2){
if (num1 > num2) {
alert(num1);}
else if (num2 > num1) {
alert(num2);}
}
If num1 is larger, then alert box with(num1) will appear ,if num2 is larger alert(num2) will appear. happy coding
Andrea Algiers
1,147 Pointshey! that wont work either bc they had me use the return function to return the proper number, now these are the next set of directions!
Beneath the max function you just created, call it with two numbers and display the results in an alert dialog. Pass the result of the function to the alert method.
For example, to display the results of the Math.random() method in an alert dialog you could type this: alert( Math.random( ) );
Mladen Ignjatovic
13,602 Pointsnum1 and num2 are just a arguments(something like placeholders) for real numbers you gonna put when you call the function. You could name them whatever you want , it doesn't matter. But you should try to give them a name in the context of a function, to make it easier for you.
You're welcome
Brandon Thompson
3,018 PointsThank you for this explanation and posts. Helped me out :)
Andrea Algiers
1,147 PointsAndrea Algiers
1,147 Pointsomg. ok that worked. I kept putting num1, num2 bc those were the numbers i used up top. so that doesnt matter??
Andrea Algiers
1,147 PointsAndrea Algiers
1,147 Pointsps. THANK YOU