FIT100 Miniquiz #6 2/11/2005 with answers
Closed Book, Closed Notes
Scoring: 1 pt. per question
Name: _____________________________
Section: ________

If you didn't do well on this quiz -- don't panic!  The important thing is to understand the material, so that when you see questions like these again (hint, hint)  you will get them right then.  Suggestion: copy the code into an HTML file to try it out.  Then make small modifications to the code to see what happens.

1. Assuming this Javascript code executes, what will be displayed?
<script language="Javascript">
for (var i = 0; i < 5; i++) {
     document.write("x");
}

A. x
B. xxxx
C. xxxxx
D. xxxxxx       
E. i

2. Assuming this Javascript code executes, what will be displayed?
<script language="Javascript">
for (var i = 1; i <= 3; i++) {
     document.write(i);
}

A. iii               
B. 1
C. 111
D. 333
E. 123

If it was write("i") instead of write(i) you would get iii for the answer

3. First study this html file.  Then answer the question.
<html>
<head>
</head>
<body>
<br>
<script language="Javascript">
for (var i = 1; i <= 3; i++) {
     if (i > 1) {
     document.write("x");
     } else {
     document.write("y");
    }
}
</script>
</body>
</html>

When the browswer loads and displays this page, what will you get?

A. x
B. xxx
C. xxy
D. xyy
E. yyy
F. yxx
G. yyx
H. y

4. First study this html file.  Then answer the question.
<html>
<head>
<script language="Javascript">
function looper(stop) {
     for (var i = 0; i < stop; i++) {
          document.write(stop);
    }
}
</script>
</head>
<body>
<br>
<script language="Javascript">
looper(2);
</script>
</body>
</html>

When the browswer loads and displays this page, what will you get?

A. stop
B. 012
C. 00
D. 22
E. 01

The parameter stop in function looper gets its value when the function is called.  In this case, that value is 2.