Assignment #2: Variables, Functions, Objects, and Events
Please NOTE: For this assignment you will make TWO HTML pages.
First, create an HTML document (either as HTML5 or XHTML doctype):
Name the document something like StockVariables.html.
Create a script section in the head section of the page,
and use JavaScript to
declare five variables.
Declare
each variable on its own statement line.
Name these variables with names which represent
five corporations that you can pretend that you are listing stock values for in your page.
For example, if
one of the stock values you want to display is for General Motors, you could name that
variable something like generalMotors.
Following the variable declarations, but still in the head section of your
page, add JavaScript statements that
assign a value (a pretend stock value) to each of the variables.
In the page's body section, use a combination of HTML tags
and JavaScript statements to
display the stock values for each of your corporations.
(Hint: use document.write() to display the stock values in the page.
And please note: You do
not
need to store the company names in the variables, just the pretend stock
values. You will put the
company names into the page with ordinary HTML text.)
Your page should look something like the following
list (with your own personal
stock companies listed) in the browser. (Don't worry if your numbers
don't look quite like these. We will discuss formatting things like
numbers, later in the semester.)
Secondly, create another HTML document (either as HTML5 or XHTML doctype):
Name this document something like SomeEvents.html.
In the page's <head>...</head> section, create (define)
a custom JavaScript function. In this function, use the alert()
built-in function to display some text that is contained in a parameter that you
put into the function definition's parentheses.
Put an onload attribute (event handler) into the page's
<body> tag. In this onload event handler, call your custom function.
Put some text into the function call's argument. I suggest that you put something like
"The page has loaded." in this text argument.
In the body section of the page, put a <button>...</button> tag which
has an onclick attribute (event handler) in it.
Call your function (again) from this button's event handler.
Put some different text into the function call's argument (meaning, make sure this text
is different from the text that you put into the first function call) (in the
body tag's event handler). I suggest that you put something like "The button was clicked." in this
text argument.
Add two hypertext links to your main
index.html file that is in your class folder. Make each of these hypertext
links display one of the two html pages that you made for this assignment.
Upload your files (there will be three of them, since you also changed your main index page) to your class folder. You will
need to use an FTP program to upload the files. You will find
some general FTP instructions on a page called "FTP
Instructions".