Custom Functions
By a custom function, we mean a function that you (the programmer) defines as opposed to one built into JavaScript.
The basic syntax is as follows:
function fred() {
JavaScript Statements
}
We used fred above for the name of the function to indicate that you get to choose the function's name.
The empty () in the function definition mean that the fred function accepts no arguments.
The JavaScript Statements in the body of the function will never be executed until you call the function by name.
If you simply call fred as shown below in your script, the JavaScript Statements will then execute.
fred();
The core concept is that you can "stash away" code in a function to be used any time you call on it.
Essentially, you pre-package code that can be used over and over again whenever you call the function.
For example, the following code would execute all the JavaScript Statements in the fred function twice.
fred();
fred();
Pre-packaged code that only executes when called upon, and that can be called upon many times,
is very useful for various programming purposes.
There is actually a function defined in a script in the source code of this example.
But it never executed since it was never called!
You should edit the source code and call the function.