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 trialVail Algatt
4,383 Pointsif-else vs if-then-else
Just curious as to what exactly the difference is between using an if-else statement versus an if-then-else statement.
Thanks!
1 Answer
LaVaughn Haynes
12,397 Points"if/then" lets you test a condition and provide instructions for when the test is true.
if(driversLicense === true){
alert("Have a nice day");
}
"if/else" lets you test a condition and provide instructions for when the test is true AND when it is false.
if(driversLicense === true){
alert("Have a nice day");
}else{
alert("Here's a ticket.");
}
"if/else if" lets you run multiple truth tests
if(driversLicense === true){
alert("Have a nice day");
}else if(isDriving === false){
alert("Get your license renewed ASAP!");
}else{
alert("Here's a ticket.");
}
__ROLLER__ Angel
25,606 Points__ROLLER__ Angel
25,606 PointsGood explanation, Thanks!