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) 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,558 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.