Complete Example
Here is a complete example of using JavaScript functions in an HTML page. Many developers prefer to put JavaScript functions in the page header as demonstrated here.
<html>
<head>
<title>JavaScript Coding</title>
<script language="JavaScript">
<!--
function SayHello(pName) {
document.write("Hello " + pName + "<br>");
}
function add(p1, p2) {
var result;
result = p1 + p2;
return result;
}
-->
</script>
</head>
<body>
<h1>JavaScript Custom Routines</h1>
<script language="JavaScript">
<!--
SayHello("Mike");
document.write("2+2=" + add(2,2));
-->
</script>
</body>
</html>