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
ian truong
4,685 Pointswhy doesnt this function run? it runs without the else clause, but it doesnt run with the else clause.
function getRandom(lower, upper){ var random = Math.floor(Math.random() * (upper - lower + 1)) + lower; var message = "get loose"; if(random > 40){ return random; } else(){ return message; } }
alert(getRandom(1,100)); alert(getRandom(2,70)); alert(getRandom(1,80));
1 Answer
Yves Robert Charles THIOR
770 Pointsit does not work with the else statement because of the parentheses you placed just between the else and the curly braces. Delete the parentheses, you should have this: if(random > 40) { return random; } else { return message; }
ian truong
4,685 Pointsian truong
4,685 Pointsi seem to forget, i thought else statement needed parentheses even if its empty?