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 trialJaime Rios
Courses Plus Student 21,100 PointsWhat's wrong with this code?
Please check the code, I'm at the Create a max() function on JavaScript Basic
function max(youA, youB) {
if (youA>youB) {
alert(youA " is larger than " youB );
}
else {
alert(youA " is larger than " youB );
}
}
1 Answer
Sam Roberton
7,225 PointsYou need to add concatenation (+)
function max(A, B) {
if (A > B) {
alert(A + " is larger than " + B);
} else {
alert(B+ " is larger than " + A);
}
}
Hope this helps :)
Jaime Rios
Courses Plus Student 21,100 PointsJaime Rios
Courses Plus Student 21,100 PointsYeah, it was also missing a return value. But thanks :D
Now it asks me to pass two numbers to the function,
function max(youA, youB) {
if (youA>youB) { alert(youA + " is larger than " + youB ); return youA; } else { alert(youA + " is larger than " + youB ); return youB } }
alert( max(4, 34) );