Programming with JavaScript

(Tutorial 7 in Textbook)

Your clients want on additional item to appear on their Web page. They are counting on selling most of their gifts during the Christmas season and want to remind their viewers of the number of shopping days left before Christmas. Just entering "There are __ days left before Christmas," would require hiring someone to update the page manually each day. It would be much better if this task could be performed automatically by a program running on the Web page itself. You will create such a program in JavaScript, a programming language designed for Web pages. For a more detailed background in JavaScript refer to tutorial seven in your textbook.

The Script Tag

The <SCRIPT> tag is a two-sided tag that identifies the beginning and end of a client-side program. Your program can be placed anywhere within the HTML file, either within the <HEAD> tags or the <BODY> tags. One problem that can be encountered with JavaScript is that older browsers might not support it. To avoid this problem, you can hide the script using comment tags (tags that will not be seen by viewers). When using comment tags within the JavaScript, you must use a set of double slashes(//) at the beginning of a line to tell the browser to ignore the line and not interpret it as a JavaScript command. The syntax for doing this is as follows:


<!---Hide this script from browsers that don't support JavaScript.

//Stop hiding from other browsers -->


Having seen the basic structure of a JavaScript program, you're ready to insert the necessary lines of code into the Just Plain Stupid text editor. Open this page in Notepad, scroll down the file until you locate the heading that reads "The Wildest and Wackiest Gifts on the Web," and place your cursor after the end heading tag. Press the enter key to place your cursor on a new line. Type in the above script.

With the <SCRIPT> tags and comments in place, your next task is to write a JavaScript program that sends output to the Web page.

Just Plain Stupid