Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 3. Syntax Validation > Time for action fixing "Alert is not defined"

Time for action fixing "Alert is not defined"

What we will do is that we will consolidate all alert() statements into one function. We can pass a parameter to that function so that we can change the messages in the alert box depending on the situation.

  1. Go back to your code, and define the following function at the top of your<script> tag:

    function alertMessage(messageObject) {
    alert(messageObject);
    return true;
    }
    

    messageObject is the parameter that we will use to hold our message.

  2. Now, change all alert() statements to alertMessage() such that the message for alert() is the same as alertMessage(). Once you are done, save the file and run the code in JSLint again.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint