DMS102/CSC170D: Introduction to Web Development
Spring 2013
Assignment 3: Scripts and Variables
-
[3 pts] Create a page that uses only a
Javascript
script element in the body of the document
to create the following content:
- A toplevel heading
- A paragraph containing one short sentence of text
- A list with two items in it
Concentrate on making your scripts readable/understandable (as well
as correct).
-
[3 pts] Create a page that asks the user for their name and their
favorite color and displays them in the body of the page.
-
[3 pts] Extend your previous script so that the favorite color is
displayed in that color. You may assume that the color is one of
the predefined CSS color names.
- [3 pts]
Create a page that asks a user first for their name, then for
their favorite color, and then for their phone number and
displays the results as a table in the page.
Things to think about
- In developing your pages/scripts, be sure you understand the
following:
- Visiting the page in a
real
browser (Firefox
recommended; Chrome or Safari usually also ok) to test its
execution.
- How to be notified of errors during your script's
execution.
- The basic development cycle for programming:
- Design
- Write the code
- Run the code (load the page)
- Works properly? You're done!
- Otherwise rewrite (go to 2) and/or redesign (go to 1)
- Repeat until done
The more you understand this now, the easier life will be as we start
developing more complicated programs. Use your lab times effectively,
especially if you are new to programming.
-
When writing a script that generates HTML (for example, with
document.write), first think what the HTML should look
like. That is, what would it be if you were writing a static
page. Then get your script to produce that HTML
using document.write. And then use variables (and perhaps
also window.prompt) to get the dynamic parts into the
HTML that you're adding to the document.
Last update: Thursday, 07-Feb-2013 09:45:46 EST