Key Words: function, method, procedure, form control, input
, id
,
onchange
, event handler, function call, function definition,
function head, formal parameter, function body, variable, variable declaration,
assignment operator, assign, getElementById()
, value
,
text, string of characters, +
, string concatenation, string,
innerHTML
.
See Wikipedia (http://www.wikipedia.org/) for a detailed
description of the key words.
You are required to have completed the objectives in Lab 8 before doing this lab.
Remember to use the online resources! When you encounter a new HTML element, look at W3School's XHTML tutorial and W3C's XHTML and HTML recommendations. When you encounter a Javascript function or want to find what you can do with an HTML element in you Javascript code, look at W3Schools Javascript tutorial and W3Schools DHTML/DOM (Dynamic HTML/Document Object Model) tutorial. You do not need to understand everything in their tutorials, but you should at least know where to find help.
The goal of this section of the lab is to practice writing if/else statements.
count
in the
HTML file. Print the variable to the screen and view the results.<script type="text/javascript"> var count = 1; document.writeln("The count is: "+count); </script>
<script type="text/javascript"> var count = 1; if (count == 0) { ready = false; } else { ready = true; count = count-1; } alert("Ready: "+ready+", Count: "+count); </script>
count
to 0. Reload the page. var count = document.getElementById("count").value;Next add the input field to the HTML document.
Enter a number: <input id="count" type="text" onchange="alertMe()">
Remember that you have to declare your function before the BODY
of your HTML. Hint:
You may need to move your Javascript code into a function!
if
statement so that when the count
is greater than 10,
ready
will be false.The goal of this section of the lab is to practice writing iteration statements and become familiar with how the for-statement works. We will also place images, which should be helpful on Project 2.
count
in your document. Next initialize
and assign the variable i
.<script type="text/javascript"> var count = 1; for (i=0; i<count; i++) { document.write("Print this text."); } </script>
document.write("The iteration variable has the value " + i + "<br>");
If the loop’s initialization sets i to 0 and limits the iteration to numbers less than 5 and increments by 1 each time, then the result should be
document.write("<img src='star.jpg' >");
The result should look like the following
Due Date: Wednesday/Thursday, November 7/8, before end of your scheduled lab.