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

JavaScript JavaScript Basics (Retired) Creating Reusable Code with Functions Create a max() Function

Can you please help me find the error?

First part of this challenge task was right but in this second task I'm not sure what's wrong? Can you please help me point out my mistake?

script.js
function max(a,b){
    if (a>b){
        alert("a is bigger");
        return a;
    } else {
        alert("b is bigger");
        return b;
    }
}

window.alert(max(20,10));

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey there,

You've pretty much got it, except the challenge did not ask for alerts inside of the if/else clause. Delete the one in the if and the one in the else and it will pass. Challenges are very picky and very strict. If you add more than was asked or not put exactly what was asked for, you will usually receive the Bummer!

Keep Coding! :) :dizzy:

Thank you Jason! Your suggestion solved the issue.