Javascript functions can be written in a javascript file or directly in an HTML document.
In both cases, when they are defined, they need to be called in order to be executed.
<html>
<head>
<style>
button {width:100px;
height:55px;
color:red;}
</style>
</head>
<body>
<button onclick="message();">PRESS</button>
<script type="text/javascript">
function message()
{
alert("This is simple function called message()");
}
</script>
</body>
</html>
<script>
function profession(name, object) {
if (object == "truck") {
return "driver";}
if (object == "ship") {
return "sailor";}
if (object == "aeroplan") {
return "pilot";}
var struka="" + name + " is " + vehicle + ".";
return struka;
}
var bus=profession("Bob","aeroplan");
document.getElementById("demo").innerHTML =bus;
</script>