Function Using return
to Communicate Time
<html><head>
<title>Functions Using return to Communicate Time</title>
<script>
function dateTime() //GET DATE TIME
{
let date = new Date();
return date;
}
function Hours() //GET HOURS
{
let theHours = dateTime().getHours();
return theHours;
}
function Minutes() //GET MINUTES
{
let theMinutes = dateTime().getMinutes();
return theMinutes;
}
function displayIt(where, whichOne) //DISPLAY ANSWER
{
document.getElementById(where).innerHTML = whichOne;
}
</script>
</head>
<body>
<button onclick="displayIt('div1', Hours());"> Hours </button>
<button onclick="displayIt('div2', Minutes());"> Minutes </button>
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>
<title>Functions Using return to Communicate Time</title>
<script>
function dateTime() //GET DATE TIME
{
let date = new Date();
return date;
}
function Hours() //GET HOURS
{
let theHours = dateTime().getHours();
return theHours;
}
function Minutes() //GET MINUTES
{
let theMinutes = dateTime().getMinutes();
return theMinutes;
}
function displayIt(where, whichOne) //DISPLAY ANSWER
{
document.getElementById(where).innerHTML = whichOne;
}
</script>
</head>
<body>
<button onclick="displayIt('div1', Hours());"> Hours </button>
<button onclick="displayIt('div2', Minutes());"> Minutes </button>
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>
Functions Using return - Displaying to One Div
<html><head>
<title>Functions Using return, Display to One Div</title>
<script>
function dateTime() //GET DATE TIME
{
var date = new Date();
return date;
}
function Hours() //GET HOURS
{
let theHours = dateTime().getHours();
return theHours;
}
function Minutes() //GET MINUTES
{
let theMinutes = dateTime().getMinutes();
return theMinutes;
}
function displayIt(whichOne) //DISPLAY ANSWER
{
document.getElementById("displayAnswer").innerHTML = whichOne;
}
</script>
</head>
<body>
<button onclick="displayIt(Hours());"> Hours </button>
<button onclick="displayIt(Minutes());"> Minutes </button>
<div id="displayAnswer"></div>
</body>
</html>
<title>Functions Using return, Display to One Div</title>
<script>
function dateTime() //GET DATE TIME
{
var date = new Date();
return date;
}
function Hours() //GET HOURS
{
let theHours = dateTime().getHours();
return theHours;
}
function Minutes() //GET MINUTES
{
let theMinutes = dateTime().getMinutes();
return theMinutes;
}
function displayIt(whichOne) //DISPLAY ANSWER
{
document.getElementById("displayAnswer").innerHTML = whichOne;
}
</script>
</head>
<body>
<button onclick="displayIt(Hours());"> Hours </button>
<button onclick="displayIt(Minutes());"> Minutes </button>
<div id="displayAnswer"></div>
</body>
</html>