Monday 16 July 2012

Javascript if else statement


<!DOCTYPE html>
<html>
<body>

<p>Click the button to get a time-based greeting.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script type="text/javascript">
function myFunction()
{
var x="";
var time=new Date().getHours();
if (time<20)
  {
  x="Nice day";
  }
else
  {
  x="Good evening";
  }
document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>

0 Responses to “Javascript if else statement”

Post a Comment