Your First Function

Things might seem a little complex until you do it the first time, so let's get you writing your first function. Follow these steps:

1.
Open your HTML template page in your favorite text editor.
2.
Start off the function by writing (in the script block) the word function and giving it a name (this one will be called yourMessage). Remember to include the parentheses at the end of the line:
<script language="JavaScript">
<!-- Cloaking device on!
function yourMessage()

// Cloaking device off -->
</script>
3.
Next, add the pair of curly braces:
<script language="JavaScript">
<!-- Cloaking device on!
function yourMessage()
{

}
// Cloaking device off -->
</script>

CAUTION

Remember to start with the opening curly brace ( ...

Get JavaScript™ 1.5 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.