| First Assignment | |
|
Task: Create a Web page that uses JavaScript to compute and
display the even integers between 0 and 10. Use File Transfer Protocol (FTP)
to install this page in the appropriate directory on the Raven server.
I. Adding JavaScript to your page Generally speaking, JavaScript statements occur within a <script> container:
... JavaScript statements here ...
</script>
The <script> container may come in various places in your markup; I prefer to put it near the bottom, after the </body> tag but before the </html> tag. II. The document.write() method Actions in JavaScript are performed by methods. To make information appear on a Web page, you'll need to put a document.write() method inside your <script> container. Here are two ways to use document.write():
document.write(variable);In the first case, the value of variable is displayed on the Web page (provided you assign a value to variable in a previous statement; if no value is given, you'll see an error message). In the second case, the word text will appear on your page. Note the double quotes, which signal that what's inside them is just text, or a "string literal." Whatever goes into the parentheses in document.write() -- the argument to the method -- will be written to the page. If the argument is a variable, the current value of the variable is written; if it is text (enclosed in quotes), then the text appears. You can mix variables and literals within a write method, thus:
document.write(x + "<p>")
Though it may seem confusing since it follows a numeric variable, the "+" operator means "append" in this case, not "add." The output is the value of the variable x followed by a linefeed or paragraph break. Note that the text in this case is an HTML tag. That's perfectly legal. III. The for loop To complete this assignment you'll need to execute document.write() once for every even integer between 0 and 10. The easiest means of repeating actions is a for loop. Here's one such loop that writes all the integers between 0 and 10, inclusive:
for(x=0; x<11; x=x+1)The loop runs 11 times, each time adding 1 to x and writing the result. On the 12th pass, when x reaches 11, the loop terminates. You will need to modify this example in two crucial ways to complete the assignment. Your modified loop must have the same pattern of punctuation (parentheses, semicolons, curly braces) as in the example, though you may change two key parts of the construction: the limit statement ("x<11") and the increment statement ("x=x+1"). The rest is for you to figure out. IV. File Transfer Protocol Once you've written your JavaScript instructions into a Web page and tested the results, save the page as Yourlastname.html (or .htm if you're a Windows user). Then use File Transfer Protocol (FTP) to move your page to the IPNM directory on raven.ubalt.edu. The login for this class is ipnm, with the password pbds753. You should see the IPNM directory as soon as you connect. Open that directory before you upload any files. If you have an Internet connection from home and have a favorite FTP package, the information above should be all you need. If you have no home connection or aren't sure about FTP, please use one of the Macintoshes in the Hypermedia Room (412 Charles Royal) during regular lab hours. All of those machines have Fetch, the standard Macintosh FTP client, available from the Apple menu. Here's what to do if you're using Fetch:
Note: these instructions assume you know how to construct a valid HTML page, how to save it (as text-only or ASCII), and how to find your way around a Macintosh if you're not able to use your own computer. These are absolute requirements for the course. |
|