2 - Javascript:Control Statements I - If statements
You should use the if statement if you want to execute some
code if a condition is true.
Syntax:
if (condition)
{
code to be executed if condition is true
}
Example
<script type="text/javascript">
//If the time on your browser is less than 10,
//you will get a "Good morning" greeting.
var d=new Date()
var time=d.getHours()
if (time<10)
{
document.write("<b>Good morning</b>")
}
</script>
Notice that there is no ..else.. in this syntax. You just tell the code to execute some code if the condition is true.
So let's experiment.