JavaScript - Functions Intro:

A function is a convenient way to group together lines of JavaScript which work together to achieve a specific result. A function is named so that it can be triggered to run (called) by using its name.

Of course, lines of JavaScript do not have to be grouped into functions in order to work. It is simply a common practice, used for its organizational benefits, and the modularity and convenience that functions provide.

Function Names:

Function Form:

A function always starts with the word function, followed by the actual name of the function, then two brackets: (). The brackets sometimes have things inside.

A function also uses the braces: {} to surround the lines of JavaScript that make up the function.

Here is an example function. Note that the function's unique name is chooseAURL.

function chooseAURL() {
  n = randInt(1,2);
  if (n == 1) return "";
  else if (n == 2) return "mypage.html";

If you forget to follow this form, expect errors.

Also, note that JavaScript requires a semicolon at end of each line of script inside the function. Don't forget the semicolons!