How to use If Else condition in Javascript
1. if statement – use this statement to execute some code only if condition is true then else condition is excluded.
2. if…else statement – use this statement to execute some code when if condition is wrong on this condition else code run.
Code:-
<script type="text/javascript"> var d = new Date(); var time = d.getHours(); if (time < 10) { document.write("This is a sunny morning!"); } else { document.write("This is a good day for you!"); } < /script>