Hour 3 covers the following topics:
Organizing scripts using functions
An introduction to conditional statements and loops
How browsers execute scripts in the proper order
Combining Tasks with Functions
Functions take parameters (the expression inside the parentheses) to tell them what to do. Additionally, a function can return a value to a waiting variable. For example, the following function call prompts the user for a response and stores it in the text variable:
text = prompt("Enter some text.")
You can also create your own functions. This is useful for two main reasons: First, you can separate logical portions of your script to make it easier to understand. Second, and more importantly, you can use the function several times or with different data to avoid repeating script statements.
You will learn how to define, call, and return values from your own functions in Hour 4, "Using Functions and Variables."