Edited at 2005/07/08 12:33:53 PST
Homework
-
Finish prelabs for chapter 13
-
Read chapters 14 and 15
-
Do prelabs for chapter 14 and 15
-
Those who have not submitted a project idea, project steps, or a bibliography: FINAL DEADLINE is Monday, July 11th.
Prelab Answers
Chapter 12 Review Questions
3. true
7. a, b, c
10. f
Chapter 12 Exercises
12.3 Write a compound conditional statement that tests whether a previously declared variable named finalScore is greater than or equal to 90, less than 90 but greater than or equal to 80, less than 80 but greater than or equal to 70, or less than 70. Do not use any logical operators (“and” or “or”). Depending on which condition is satisfied, the code should display an alert box message with an appropriate message (e.g., “Final score is in the 80s” or “Final score is below 70”).
if (finalScore >= 90) {
alert("Final score is in the 90s")
}
else if (finalScore >= 80) {
alert("Final score is in the 80s")
}
else if (finalScore >= 70) {
alert("Final score is in the 70s")
}
else {
alert("Final score is below 70")
}
Note: Because the if and else code blocks each have only one statement inside them, the curly braces are optional, i.e., the code could be written as:
if (finalScore >= 90)
alert("Final score is in the 90s")
else if (finalScore >= 80)
alert("Final score is in the 80s")
else if (finalScore >= 70)
alert("Final score is in the 70s")
else
alert("Final score is below 70")
Note also: The final else clause does not require an if statement (i.e., else if (finalScore < 70) ), because by that point all the other previous conditions have proven to be false, so the finalScore value must be less than 70.
12.7 Write the HTML code for a form named actorQuestion with a set of radio buttons named actorsRB. The purpose of the form is to ask the surfer to indicate his or her favorite male actor: Arnold Schwarzenegger, Tom Hanks, Sylvester Stallone, Tom Cruise, John Wayne, Harrison Ford, Robert Redford, Brad Pitt, or Other. The set of radio buttons should be displayed in a vertical column.
(NOTE: This problem was slightly modified from the original mss version.)
<form id="actorQuestion" name="actorQuestion">
Please indicate your favorite male actor:<br />
<input type="radio" name="actorsRB" />Arnold Schwarzenegger<br />
<input type="radio" name="actorsRB" />Tom Hanks<br />
<input type="radio" name="actorsRB" />Sylvester Stallone<br />
<input type="radio" name="actorsRB" />Tom Cruise<br />
<input type="radio" name="actorsRB" />John Wayne<br />
<input type="radio" name="actorsRB" />Harrison Ford<br />
<input type="radio" name="actorsRB" />Robert Redford<br />
<input type="radio" name="actorsRB" />Brad Pitt<br />
<input type="radio" name="actorsRB" />Other<br />
</form>
12.8 Write the JavaScript code that will test which radio button in Problem 12.7 is checked and display the message “You chose Schwarzenegger” or “You chose Redford” (or whatever) in a textbox named outputBox belonging to the same form.
if (actorsRB[0].checked == true) {
alert("You chose Schwarzenegger")
}
else if (actorsRB[1].checked == true) {
alert("You chose Hanks")
}
else if (actorsRB[2].checked == true) {
alert("You chose Stallone")
}
else if (actorsRB[3].checked == true) {
alert("You chose Cruise")
}
else if (actorsRB[4].checked == true) {
alert("You chose Wayne")
}
else if (actorsRB[5].checked == true) {
alert("You chose Ford")
}
else if (actorsRB[6].checked == true) {
alert("You chose Redford")
}
else if (actorsRB[7].checked == true) {
alert("You chose Pitt")
}
else if (actorsRB[8].checked == true) {
alert("You chose Other")
}
Note: Because the if and else if code blocks each have only one statement inside them, the curly braces are optional. Also, the conditions may be written without the ==true . And the last condition may simply be an else without the if condition for "You chose other":
...
else {
alert("You chose Other")
}
Chapter 13 Review Questions
1. c and e
3. false (the index should be 3, not 4)
6. a
8. b
Chapter 13 Problems
13.2
<form id="vpQuestion" name="vpQuestion">
Which of the following Presidents also served as Vice President of the United States?<br />
<input type="checkbox" name="trooseveltCB">Theodore Roosevelt<br />
<input type="checkbox" name="frooseveltCB">Franklin Roosevelt<br />
<input type="checkbox" name="trumanCB">Harry Truman<br />
<input type="checkbox" name="kennedyCB">John F. Kennedy<br />
<input type="checkbox" name="nixonCB">Richard Nixon<br />
<input type="checkbox" name="reaganCB">Ronald Reagan<br />
</form>
13.4
if (document.vpQuestion.trooseveltCB.checked) {
quizScore = quizScore + 1
}
if (document.vpQuestion.frooseveltCB.checked) {
quizScore = quizScore - 1
}
if (document.vpQuestion.trumanCB.checked) {
quizScore = quizScore + 1
}
if (document.vpQuestion.kennedyCB.checked) {
quizScore = quizScore - 1
}
if (document.vpQuestion.nixonCB.checked) {
quizScore = quizScore + 1
}
if (document.vpQuestion.reaganCB.checked) {
quizScore = quizScore - 1
}
13.6
var allcapsName = document.infoForm.userNameBox.value.toUpperCase()
if (allcapsName == "JAMES") {
document.infoForm.greetingBox.value = "Good to see you again, Mr. Bond"
}
13.8
<!--XHTML and DTD info goes here-->
<html>
<head>
<script type="text/javascript")
function changeImage() {
var randomNumber = Math.floor(10*Math.random()) + 1
if (document.images==true) {
if (randomNumber == 1) {
document.slideShow.src = "image1.jpg"
}
else if (randomNumber == 2) {
document.slideShow.src = "image2.jpg"
}
else if (randomNumber == 3) {
document.slideShow.src = "image3.jpg"
}
//etc. for 4 through 9
else if (randomNumber == 10) {
document.slideShow.src = "image10.jpg"
}
}
setTimeout("changeImage()", 2000)
}
</script>
</head>