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
Anthony Boardman
4,672 PointsCall the function and display the results in an alert dialogue.
Can anyone help with this question, it's killing me I've passed the whole of this course it's just this last question that I'm stuck on!!
"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: alert( Math.random( ) ); "
This is the code I've got from the challenge before:
function max(lower, higher){
if(lower > higher){
return lower;
} else {
return higher;
}
6 Answers
Iago Wandalsen Prates
21,699 PointsWhat it wants you to do is alert the result of the function.
alert(max(arg1, arg2));
And replace the arg1 and arg1 by whatever its asking you to.
ps: the variable names you are using are not good, I mean, having a parameter called lower, makes you assume that the parameter must be lower than the other. As you wont know which one is bigger, just give it generic names like num1 and num2
Maria Stommes
17,140 PointsI think they want you to pass in actual values for the arguments. I did this and it passed:
alert(max(10, 12));
Alexander Rasmussen
12,901 Pointsi am not sure, but try
alert( Math.random( max) );
after the function
Sun Kim
1,443 PointsHi, I've read the comments here, but still I cannot get the right answer to the question. I've tried several and this is one of them... Your help will be really appreciated.
var bigNumber = "";
function max(a, b) { if (a > b) { return bigNumber = a; } else { return bigNumber = b; } } alert(bigNumber());
DJ Covington
2,706 PointsSun Kim,
you need to alert( max() ) instead of alert(bigNumber());
Also I am fairly new to JavaScript also but I do not think that you can return the same variable with different values.
var bigNumber= ""; // this is not needed also you declared a variable with no value???
function max(a, b){
if{
return bigNumber = a; // bigNumber cannot be defined here. I recommend you research the return statement for javascript
}
else {
return bigNumber = b; // bigNumber cannot be used twice for a separate value.
}
}
alert(bigNumber()); // you cannot call a return value. That defines the point of making a function if that is even possible. // Your function will not work at all! You have too many broken pieces!
I took your function and made it work. I hope this helps
function max(a, b) { if (a > b) { return a; } else { return b; } }
alert(max(15, 35));
I know that this is a late reply but it might help someone else!
Sean Flanagan
33,237 PointsHi DJ Covington.
Just to let you know that your reply has helped someone else, me.
Thanks
Sean
DJ Covington
2,706 PointsNO PROBLEM!!! Thanks that I can contribute to the team
Christian Linnerud
7,312 PointsThis set up worked for me.
max();
alert( Math.random() );