Articles HTML Tutorial CSS Tutorial JavaScript Tutorial PHP Tutorial MYSQL Tutorial Contact Us
JAVASCRIPT If Else

If Else statements allow you to check if a certain condition is true, and do something, and if it's not true, do something else instead.

You can use the if statement on it's own: <script>
condition=true;

if(condition){
alert('Condition is True');
}
</script>

Or you can use the if statement with an else statement: <script>
condition=true;

if(condition){
alert('Condition is True');
}
else{
alert ('Condition is False');
}
<script>

You can even combine if & else statements together: <script>
condition='c';

if(condition=='a'){
alert('Condition is A');
}
else if(condition=='b'){
alert('Condition is B');
}
else{
alert('Condition is C');
}
<script>


There's not a lot else to discuss regarding if else... it's that simply, and you'll use them alot!