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 trialMathew Yangang
4,433 Pointscalling functions
The instruction says beneath the max function call it with two numbers and create an alert dialog box . The problem is when i do that, i get a message that the code is no longer passing. Any idea please?
a=1;
b=2;
function max(a,b){
if(b>a);
max(1,2);
alert(Math.random(1)*2):
return (b);
}
alert(Math.random(1)*2);
1 Answer
Steven Parker
231,271 PointsOnce you pass task 1, you should not make any changes to the function. In task 2 you just call the function from new code you add below it.
There are several issues now that prevent the function from working, including:
- an "if" statement should not have a semicolon after the conditional expression
- the function should not call itself
- there should be two different returns, one will be used based on the comparison
- there should be no "alert" call inside the function
And when you do create the alert and call the function, you won't need to use "random".