JavaScript If…Else
JavaScript Tutorial » JavaScript If…Else
JavaScript Conditional Statements
There are several conditional statements in JavaScript
1. if statement,
2. if...else statement,
3. if...else if....else statement,
4. switch...case statement
if Statement - example
if statement is used to execute a block of code only if the specified condition is true.
// Code to be executed
}
<script>
var now = new Date();
var dayOfWeek = now.getDay(); // Sunday - Saturday : 0 - 6
if(dayOfWeek == 5) {
alert("Have a nice weekend!");
}
</script>
if...else Statement - example
if...else statement allows you to execute one block of code if the specified condition is evaluates to true and another block of code if it is evaluates to false.
// Code to be executed if condition is true
} else {
// Code to be executed if condition is false
}
<script>
var now = new Date();
var dayOfWeek = now.getDay(); // Sunday - Saturday : 0 - 6
if(dayOfWeek == 3) {
alert("Have a nice weekend!");
} else {
alert("Have a nice day!");
}
</script>
Have a nice day!
if...else if...else Statement, example
The if...else if...else a special statement that is used to combine multiple if...else statements.
// Code to be executed if condition1 is true
} else if(condition2) {
// Code to be executed if the condition1 is false and condition2 is true
} else {
// Code to be executed if both condition1 and condition2 are false
}
<script>
var now = new Date();
var dayOfWeek = now.getDay(); // Sunday - Saturday : 0 - 6
if(dayOfWeek == 5) {
alert("Have a nice weekend!");
} else if(dayOfWeek == 0) {
alert("Have a nice Sunday!");
} else {
alert("Have a nice day!");
}
</script>
JavaScript If…Else string contains, or, undefined, not null, and, not, checkbox is checked, has class, shortheand: online, if, example, ternary, condition, inline, alternative, break, ejemplo
JavaScript If…Else - javascript tutorial
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

Find here examples of creative and unique website layouts.

Find here examples of creative and unique website CSS HTML menu.