Use the else, when if is not true.
<html>
<body>
<script>
bananas = 22
if (bananas == 6)
{
alert("It's true. We have a half dozen of bananas.")
}
else
{
alert("It's not true. We have another quantity of bananas.")
}
</script>
</body>
</html>
In this example we are using the
if else.
Explanation: If (
if) the number of bananas is equal to 6, do alert("It's true. We have a half dozen of bananas."). Else (
else), do alert("It's not true. We have another quantity of bananas.").
So simple, isn't it?