Function Using return - Date Object getHours
<html><head>
<title>Function Using return - Date Object getHours</title>
<script>
function theHours()
{
var date = new Date();
var hours = date.getHours(); //0 to 23
return hours;
}
function messageHours()
{
let hoursMessage;
console.log(theHours());
if(theHours() >= 0 && theHours() < 6)
{
hoursMessage = "Its Early Morning";
}
else if(theHours() >= 6 && theHours() < 12)
{
hoursMessage = "Its Mid Morning";
}
else if(theHours() >= 12 && theHours() < 18)
{
hoursMessage = "Its Afternoon";
}
else if(theHours() >= 18 && theHours() <= 23)
{
hoursMessage = "Its night time";
}
document.getElementById("hoursDisplay").innerHTML = hoursMessage;
}
</script>
</head>
<body onload = "messageHours();">
<div id="hoursDisplay"></div>
</body>
</html>
<title>Function Using return - Date Object getHours</title>
<script>
function theHours()
{
var date = new Date();
var hours = date.getHours(); //0 to 23
return hours;
}
function messageHours()
{
let hoursMessage;
console.log(theHours());
if(theHours() >= 0 && theHours() < 6)
{
hoursMessage = "Its Early Morning";
}
else if(theHours() >= 6 && theHours() < 12)
{
hoursMessage = "Its Mid Morning";
}
else if(theHours() >= 12 && theHours() < 18)
{
hoursMessage = "Its Afternoon";
}
else if(theHours() >= 18 && theHours() <= 23)
{
hoursMessage = "Its night time";
}
document.getElementById("hoursDisplay").innerHTML = hoursMessage;
}
</script>
</head>
<body onload = "messageHours();">
<div id="hoursDisplay"></div>
</body>
</html>