Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics (Retired) Making Decisions with Conditional Statements Improving the Random Number Guessing Game

Adam Maley
Adam Maley
5,946 Points

So else doesn't have a () or condition ever?

So else doesn't have a () or condition ever?

Would you ever see this

else () { alert("You win!"); }

Also.... on the alerts and window messages which is correct to do with the ; if else (){ alert ("tacos");
}


if else (){ alert("tacos") }

1 Answer

andren
andren
28,520 Points

It never has a condition or a parenthesis, that is correct.

The point of the else statement is that it automatically runs if the if/else if statements above it does not. Also as far as semicolons go your first example:

if else (/* Condition goes here */){ 
    alert("tacos");
}

Is correct. The one thing about semicolons and if/else if statements that you have to be very careful about is that you should never place a semicolon after the parenthesis containing its conditions. If you do then the statement will be terminated prematurely. And the code you placed in the body of the if/else if will be executed regardless of whether the conditions evaluated to true or not.