The time and numbers to the right were executed from this code.

<script>
	var d = new Date();
   	 var n = d.toLocaleTimeString();
	TimeReport2()
</script>

<br />
<button onclick="TimeReport5()">Call the Time</button>

<p id="demo5"></p>


<p id="demo2"></p>
<p id="demo3"></p>

<script type="text/javascript">

var x = myFunction(4, 3);
document.getElementById("demo2").innerHTML = x;

var y = myFunction(40, 30);
document.getElementById("demo3").innerHTML = y;


function myFunction(a, b) {
  return a * b;
}
</script>
//////////////////////////////////////////////

Here are 2 scripts written in the head.

function TimeReport2() { document.write (n); } function TimeReport5() { var d = new Date(); var n = d.toLocaleTimeString(); document.getElementById("demo5").innerHTML = n; }

The first time function called
is from the javascript library as follows:.

function TimeReport3() { var d = new Date(); var n = d.toLocaleTimeString(); document.write (n); }


JavaScript Functions for Time

After reporting the time,
this example calls a function which performs a calculation and returns the result:

Functions can be moved to a Javascript Library.

The top time is reported by a one line function call: <script>TimeReport3()</script>

This one line call does not recognize the method: document.getElementById("demo").innerHTML = n;

Instead, it recognizes the old document.write method.