Assignments    Calendar/Schedule    Table of Contents    Resources    |    MY Assignments    My HOME

Martha's COIN 70b Midterm Practice

Testing Forms

1 A B C
2
3
4


Questions and Answers

CODE: red = intended answer; blue = actual answer, in addition or instead of intended; red = did not answer during exam; correct answer
ASSESSMENT: Got 23 of 25 right. Foolish error on 17 (b instead of c); #3 has error: = should be ==. DRATS!

   1.  If welcome = "Welcome to ", how do you get "Welcome to JavaScript & VBScript"
      A. welcome += "JavaScript & VBScript";
                 document.write(welcome);
      B. greetings = welcome + "JavaScript & VBScript";
                document.write(greetings);
      C. greetings = "Welcome to " + "JavaScript & VBScript";
                document.write(greetings);
      D. none of the above

   2. false || true && false is
      A. true
      B. false
SOURCE: Text; REASONing before test: false && true = false; false OR false = true;
ACTUAL REASON: logical OR takes precedence.  SO, F or T = T; T && F = FALSE!

3. var response = 100; var answer = 100; if (response = answer) alert("Correct"); else alert("Incorrect"); A. alert("Correct") will appear B. alert("Incorrect") will appear C. an error message will appear in some browsers (is this possible?) D. none of the above RESULT: REASON - Correct shows up because alert("Correct") shows Correct in an alert. 4. How do you refer to the third element of the second form on a page? A. document.forms[2].elements[2] B. document.forms[0].elements[1] C. document.forms[1].elements[2] D. document.forms[1].elements[3] QUESTION: How do you print out the names of the elements of the forms of a document? ANSWER: displayElementNames.html function DisplayElementNames() { for (i = 0; i < 4; i++) { alert('document.formName.elements[' + i + '].name is\n\n"' + document.formName.elements[i].name + '"'); } } Use the information below for question 5 var URL = "http://sislands.com"; var SI = "Solution Islands"; document.write("<A HREF="+ URL + ">" + SI + "</A>"); document.write(SI.link(URL)); 5. The two document.write()s above will produce the same results A. true B. false RESULTS:
SOURCE: Text 6. var JFK = "Ask not what your country can do for you..."; <INPUT TYPE="BUTTON" VALUE="Kennedy" onClick="Quotes(JFK);"> A. Quotes() is passing a literal B. Quotes() is passing a variable C. Quotes() is passing an object D. none of the above RESULTS:
SOURCE: Text; Literal; Variable; Object(this.value); Object(this.name); Form(this) 7. When you pre-load an image, where is it stored? (Choose the BEST answer) A. on the server B. in the document Object C. in an Image Object D. in a Variable SOURCE: Text - Images; JavaScript makes it possible for you to Pre-load images and
store them in Image Objects that don't appear on the page.
ALTERNATE ANSWER: Coding Forums; All preloading means is that they are downloaded to the users cache, which means you dynamically swap, or change, between images. 8. Which of the following is a Method that makes JavaScript animation possible? A. timer() B. setTimeout() C. countdown() D. wait() SOURCE: Animated Rollover Buttons Tutorial Use the information below for question 9 var color = prompt ("Please enter a color", "blue"); var sentence = prompt ("Please enter a sentence", "Hello World"); document.write("<B&'<FONT COLOR=" + color + ">" + sentence + "</FONT></B>"); document.write(sentence.fontcolor(color).bold()); 9. The two document.write()s above will produce the same results A. true B. false RESULTS: SOURCE: String Methods for HTML Formatting 10. Math.round(2.500000) will equal A. 3 B. 2 C. 2.5 D. none of the above SOURCE: Math Object 11. Which Method can you use to determine the sixth character in a text string called "txt"? A. txt.position(6) B. txt.charAt(5) C. txt.charAt(6) D. txt(6) SOURCE: Displaying Subsets of Strings 12. If you want to use the substring() Method to pull the first four letters out of a text string called "txt", which arguments should you use? A. txt.substring(1, 4) B. txt.substring(0, 3) C. txt.substring(4) D. txt.substring(0, 4) SOURCE: Displaying Subsets of Strings; CHECK THIS OUT AGAIN! Use the following information to answer questions 13 – 15 function writefld() { var fld = "Yo!"; document.forms[1].elements[1].value = fld; } function writertn(expression) { var fld = expression; return fld; } <FORM> <INPUT TYPE="text" NAME="Name" VALUE="bla bla bla"> <INPUT TYPE="button" VALUE="Write" onClick="document.forms[1].Name.value= 'Yo!';"> <INPUT TYPE="button" VALUE="writefld" onClick="writefld();"> <INPUT TYPE="button" VALUE="writertn" onClick="document.forms[2].elements[2].value= writertn('Yo!');"> </FORM> <FORM> <INPUT TYPE="text" NAME="Name" VALUE=""><BR> <INPUT TYPE="text" VALUE=""><BR> <INPUT TYPE="text" VALUE=""><BR> <INPUT TYPE="submit" VALUE="Push me" onClick="alert('Yo')"> </FORM> SOURCE: Text - Object Hierarchy NOTE: see form1 at top of page PROBLEM: This doesn't make any sense. There is not a function for WRITE; why does it work?
ANSWER: because it is written there in the code: onClick="document.forms[1].Name.value= 'Yo!';"!! 13. Pressing Button "A" will put "Yo!" into text box A. 1 B. 2 C. 3 D. none of the above 14. Pressing Button "B" will put "Yo!" into text box A. 1 B. 2 C. 3 D. none of the above 15. Pressing Button "C" will put "Yo!" into text box A. 1 B. 2 C. 3 D. none of the above 16. if minutes = 9 & timeSt = ((minutes < 10) ? ":0" : ":") + minutes; then timeSt equals A. :0 B. :09 C. :9 D. 9 SOURCE: Annotated Digital Clock 17. parseFloat("3.14 meters") will return A. 3 B. 314 C. 3.14 D. NaN SOURCE: parseFloat.html 18. <INPUT TYPE="BUTTON" VALUE="Kennedy" onClick="Quotes(this);"> A. Quotes() is passing the form object B. Quotes() is passing the button object C. Quotes() is passing the VALUE="Kennedy" D. none of the above SOURCE: Text; Literal; Variable; Object(this.value); Object(this.name); Form(this) 19. Which of the following is a Property of the document Object? A. bgColor B. BGColor C. bgcolor D. none of the above SOURCE: HTML String Methods and document Object - Properties 20. JavaScript scripts can only occur within the <script></script> tags A. true B. false SOURCE: How Do You Use JavaScript? and Scripts and Locations - Method 2 21. What are ways to trigger functions A. Mouse actions B. onLoad C. calling functions within scripts D. calling a function within a function SOURCE: So What is a Function? Use the information below for questions 22 - 25 <SELECT NAME="example" onChange="go2(this);">
<OPTION VALUE="Number One" SELECTED>1</OPTION>
<OPTION VALUE="The Second">2</OPTION>
<OPTION VALUE="Three is It">3</OPTION>
</SELECT> TEST - selectOptions.html 22. when the list is first displayed, example.options[1].value = A. "Number One" B. "The Second" C. 1 D. none of the above 23. If the user then clicks on the menu and selects the second option, the onChange event handler would execute (the go2(this) function would be called), and then the value of example.options[1].value = A. "Number One" B. "The Second" C. 1 D. none of the above 24. example.options[0].defaultSelected = A. true B. false C. 1 D. 0 25. If the user then clicks on the menu and selects the second option, the onChange event handler would execute (the go2(this) function would be called), and then the value of example.selectedIndex = A. 0 B. 1 C. 2 D. none of the above SOURCE: the Select Element and the Select Object QUIZ (I got 1 of 10!), comments and selectOptions

RETURN