2530 loCM Website
Assignments
Posted by senchent at 2005/07/27 18:42:26 PST

awwwww... it's the last day of ATDP ; - (

Homework

  • FINISH WEBSITE BY BEGINNING OF CLASS

  • BRING FOOD (SEE FORUM) FOR PARTY!!!!


Posted by senchent at 2005/07/25 15:08:50 PST

Homework

  • Keep working on websites and turn in another project report.


Posted by senchent at 2005/07/22 09:29:10 PST
Edited at 2005/07/22 10:22:05 PST

Homework

  • Finish written portion of the project by Monday. If you finish it over the weekend, please e-mail it to Elena at LNA@berkeley.edu


Posted by senchent at 2005/07/18 10:51:06 PST
Edited at 2005/07/18 10:58:35 PST

Homework

  • Complete evaluations and bring in Wednesday.

  • Finish all missing/incomplete labs

  • Continue developing your webpage/project.

  • Submit project report


Posted by senchent at 2005/07/15 10:16:42 PST
Edited at 2005/07/15 10:23:43 PST

Homework

  • Read and collect information on your project from the library

  • Revise/refine the website layout

  • Write a short progress report as to what you have accomplished between Friday and Monday.

  • Pick three URLs of your choice and grade the websites based on design and content (information)


Posted by senchent at 2005/07/14 11:49:41 PST
Edited at 2005/07/15 10:16:56 PST

Homework

Here is what you should include for the Progress Report for the projects:

1) Refinement of Topic

Refined and narrowed it from initial proposals.

2) Objectives/Motivations

Refined and narrowed it from initial proposals.

3) Updated and summary of sources

Include an updated list of all the sources you’ve collected so far

4) Outline of the project
Either a detailed (meaning use complete sentences) outline or breakdown your project into several modules (like a table contents) and provide a paragraph or two about what you will include in each of them. (download example*)

5) Comments
What is going well or not going well on your project? Write a short paragraph of progress of your research.

*You will need Microsoft Word to view this document. If you cannot view it, click here and scroll down to the examples.


Posted by senchent at 2005/07/11 12:38:51 PST
Edited at 2005/07/15 08:20:28 PST

Homework

  • Page layout assigment .DOC download

  • NO READING! WOOO! (unless you need to make any up, that is!)

Prelab Answers

Chapter 14 Review Questions

NOTE: The review questions for Chapter 14 were inadvertently left out of the mss, so they're included here.

5. b
7. a
9. b
10. b and c

Chapter 14 Exercises

14.6 Write the JavaScript code that creates three arrays, each with 100 elements, and named countingNumbers, evenNumbers, and oddNumbers. Then use a for loop to fill the countingNumbers array with the numbers 1 to 100, another for loop to fill the evenNumbers array with the numbers 2 to 200, and a third for loop to fill the oddNumbers array with the numbers 1 to 199.

Answer:
var countingNumbers = new Array(100)
var evenNumbers = new Array(100)
var oddNumbers = new Array(100)
var ctr

for (ctr=0; ctr<=99; ctr++) { //May also use ctr<100 instead of ctr<=99
countingNumbers[ctr] = ctr + 1 //Could also have the loop go from 1 to 100 and then
} // write countingNumbers[ctr-1] = ctr

for (ctr=0; ctr<=99; ctr++) { //May also use ctr<100 instead of ctr<=99
evenNumbers[ctr] = 2*(ctr+1) //Could also have the loop go from 1 to 100 and then
} // write evenNumbers[ctr-1] = 2*ctr

for (ctr=0; ctr<=99; ctr++) { //May also use ctr<101 instead of ctr<=100
oddNumbers[ctr] = 2*(ctr+1) – 1 //Could also have the loop go from 1 to 100 and then
} // write oddNumbers[ctr-1] = 2*ctr - 1

14.7 Write the JavaScript code that uses a prompt box to ask the surfer to enter a number from 2 to 10. Then create an array with that number of elements (i.e., whatever number the surfer entered) and use a for loop to fill the array completely with random numbers between 0 and 1. (Use the random number function covered in Chapter 11.)

Answer:
var theNumber = prompt("Please enter a number from 2 to 10", " ")
var randomNumbers = new Array(theNumber)
var ctr
for (ctr=0; ctr<theNumber; ctr++) { //May also use ctr<=(theNumber-1) instead of
randomNumbers[ctr] = Math.random() // ctr<theNumber
}

14.10 Write the code for a function named maxValue() with two parameters, named theArray and numValues. The function should use a loop and a conditional statement to find the maximum value in the array and then return that value.

Answer:
The basic algorithm to find the max value in the array is as follows:
1. Declare a variable named theMax, which will store the maximum value.
2. Set the value of theMax to the first value in the array. In other words, we start off by assuming that the first value in the array is the maximum value.
3. Proceed through the array one element at a time using a for loop. For each element, use a conditional statement to check if the value of the element is greater than the value stored in theMax. If it is greater, then we make that value the new value of theMax and continue to the next element. If it isn’t, we do nothing and continue to the next element.
4. Once we have gone through the whole array, the true maximum value will be stored in theMax.

Code:
function maxValue(theArray, numValues) {
var theMax = theArray[0]
for (ctr=1; ctr<numValues; ctr++) {
if (theArray[ctr] > theMax) {
theMax = theArray[ctr] //Change the value of theMax to the new greater value
}
}
return theMax
}

14.11 Rewrite the question1 and question2 conditional statements at the beginning of Section 14.5.2 so that they use the forms array. Then rewrite them again using a for loop so that the code only has one compound conditional statement (inside the loop). Show the change you would make to the loop if there were twenty-five questions instead of just two.
(NOTE: This question was slightly revised from the original mss version—the word “compound” was added before “conditional statement”.)

Answer:
The key change is to replace the form name question1 with forms[0] and the form name question2 with forms[1]:

var scoreA = 0, scoreB = 0, scoreC = 0
if (document.forms[0].choiceRB[0].checked) {
scoreA = scoreA + 1
}
else if (document.forms[0].choiceRB[1].checked) {
scoreB = scoreB + 1
}
else if (document.forms[0].choiceRB[2].checked) {
scoreC = scoreC + 1
}

if (document.forms[1].choiceRB[0].checked) {
scoreA = scoreA + 1
}
else if (document.forms[1].choiceRB[1].checked) {
scoreB = scoreB + 1
}
else if (document.forms[1].choiceRB[2].checked) {
scoreC = scoreC + 1
}

Rewrite as a for loop:

var ctr
for (ctr=0; ctr<2; ctr++) { //May also use ctr<=1 instead of ctr<2
if (document.forms[ctr].choiceRB[0].checked) {
scoreA = scoreA + 1
}
else if (document.forms[ctr].choiceRB[1].checked) {
scoreB = scoreB + 1
}
else if (document.forms[ctr].choiceRB[2].checked) {
scoreC = scoreC + 1
}
}

Modifying the for loop for 25 questions:

for (ctr=0; ctr<25; ctr++) { //May also use ctr<=24 instead of ctr<25
//Same conditional statement code as above
}

Chapter 15 Review Questions

2. d
8. a
10. c

Chapter 15 Exercises

15.3

var firstLetter1 = customer1.charAt(0) //customer1.substring(0,1) could also be used
var firstLetter2 = customer2.charAt(0)
if (firstLetter1 < firstLetter2) {
document.resultsForm.sortBox.value = customer1 + ", " + customer2
}
else if (firstLetter1 > firstLetter2) {
document.resultsForm.sortBox.value = customer2 + ", " + customer1
}
else {
document.resultsForm.sortBox.value = "Both customer names start with the same letter."
}

15.5

The code for the form will be:
<form id="londonForm" name="londonForm">
<input type="button" name="b1" value="Display London Time" onclick="londonTime()" /><br />
Day of week (0 = Sunday): <input type="text" name="dayBox" size="1" /><br />
Hours: <input type="text" name="hoursBox" size="2" /><br />
Minutes: <input type="text" name="minutesBox" size="2" /><br />
</form>

Where the function is:
function londonTime() {
var currentDate = new Date() //Create date object
document.londonForm.dayBox.value = currentDate.getUTCDay()
document.londonForm.hoursBox.value = currentDate.getUTCHours()
document.londonForm.minutesBox.value = currentDate.getUTCMinutes()
}

15.9

function setDateCookie() {
var currentDate = new Date()
var currentMonth = currentDate.getMonth()
var currentDayOfMonth = currentDate.getDate()
var expDate = currentDate.setMonth(currentMonth + 9)
document.cookie = "lastVisitMonth=" + currentMonth + ";expires=" + expDate.toGMTString()
document.cookie = "lastVisitDate=" + currentDayOfMonth + ";expires=" + expDate.toGMTString()
}


Posted by senchent at 2005/07/08 08:08:07 PST
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>


Posted by senchent at 2005/07/06 16:40:07 PST
Edited at 2005/07/08 08:58:56 PST

Homework

  • Read chapters 12 and 13

  • Do Prelabs for 12 and 13

  • Listen to the webcast lecture about using the UC Berkeley library search engines

  • Find 2-3 books via the UC Berkeley library search

  • NOTE: Remember to bring your IDs (yellow cards) on friday, so you can have access to the library.

Prelab Answers

Chapter 10 Review Questions

6. formal parameters, actual parameters
7. d

Chapter 10 Exercises

10.2 Write the HTML code that would create a form with four textboxes, displaying them with two on the first line and two on the second line. Give them each a width of 15 characters. Each box should initially appear with the text “Box 1” (or “Box 2”, etc.) in it, except the last one, which should be empty.

<form id="sampleForm" name="sampleForm">
<input type="text" name="firstBox" value="Box 1" size="15" />
<input type="text" name="secondBox" value="Box 2" /><br />
<input type="text" name="thirdBox" value="Box 3" />
<input type="text" name="fourthBox" />
</form>

10.6 For each of the following cases, write the code for a function named processResults:
(a) The function receives the value of a textbox and stores it in a formal parameter named theMessage. The code in the function copies the value of the textbox into another textbox named outputBox that belongs to a form named messageDisplay.
(b) The function receives two textbox objects themselves and stores them in formal parameters named box1 and box2. The code in the function copies the value of box1 into box2.

(a)
function processResults(theMessage) {
document.messageDisplay.outputBox.value = theMessage
}

(b)
function processResults(box1, box2) {
box2.value = box1.value
}

10.7 Repeat Problem 10.6 for the following cases:
(a) The function receives the value of a textbox and stores it in a formal parameter named theMessage. It also receives a textbox object and stores it in a formal parameter named theMessageBox. The code in the function copies the value of theMessage into the textbox represented by the parameter theMessageBox.
(b) The function receives a form and stores it in a formal parameter named theForm. The original form has two textboxes named inputBox and outputBox. The code in the function copies the value of inputBox into the outputBox.

(a)
function processResults(theMessage, theMessageBox) {
theMessageBox.value = theMessage
}

(b)
function processResults(theForm) {
theForm.outputBox.value = theForm.inputBox.value
}

10.10 Write the HTML code for a form with three textboxes named ageBox, genderBox, and schoolyearBox, appropriately labeled. The form should use a submit button to email the information in the boxes to the address studentsurvey@anonymouspollster.org. The form should also implement a reset button.

<form method="post" enctype="text/plain" action="mailto:studentsurvey@anonymouspollster.org">
Please enter your age:<br />
<input type="text" name="ageBox" size="3" /><br />
Please enter your gender (M or F):<br />
<input type="text" name="genderBox" size="1" /><br />
Please enter your school year (Frosh, Soph, Jr, or Sr):<br />
<input type="text" name="schoolyearBox" size="5" /><br />
<input type="submit" value="Submit information" />
<input type="reset" value="Erase info and start over" />
</form>

Chapter 11 Review Questions

1. c
4. a, b, c, and d
5. d
9. c

Chapter 11 Exercises

11.1

(a) A loosely typed programming language is a language that allows a given variable to store different types of values at different times. For example, at one point it might contain a number value and at another point a string value. (A strongly typed language does not allow this flexibility—any given variable may only store one type of value.)

(b) A boolean value is a value that is either true or false.

(c) Variable scope refers to where in a script or program a variable may be used. A variable with local scope (a local variable) may only be used inside the function within which it is declared. A variable with global scope (a global variable) may be used anywhere in a source document.

11.2

A local variable is declared inside a function and may only be used inside that function. A global variable is declared outside of a function (but in a <script> element of course) and may be used in any <script> element in that source document. Global variables are convenient because, once declared, they may be used anywhere in the document. But such global use can lead to programming errors in longer programs. So in general it is better to make your variables local ones whenever possible.

11.4

<script type="text/javascript">
function testingVariables() {
var num1 = 19.54
var name3 = "Theodore Roosevelt"
var matchFound = true
num1 = 29.1
name3 = "Abraham Lincoln"
matchFound = false
}
</script>

11.7

<script type="text/javascript">
var luckyNumber = 10*Math.random() //The var keyword is not required
var luckyNumber2 = Math.floor(100*Math.random()) + 1
</script>

11.10

<script type="text/javascript">
var hallOfFamer //Declare global variable (use of var is optional)

function fullName(firstName, lastName) {
var theName //Could also write these two lines as one line:
theName = firstName + " " + lastName // var theName = firstName + " " + lastName
return theName
}

hallOfFamer = fullName("Babe", "Ruth")
</script>


Posted by senchent at 2005/07/01 10:34:06 PST
Edited at 2005/07/08 09:03:23 PST

Homework

  • Finish lab exercises for chapter 9 if not done so already.

  • Read chapter 10.

  • Do prelabs for chapter 10.

  • Project: Bring a list of bibliographic references related to your topic (books, journals, internet sources, newspapers, etc)

Prelab Answers

Chapter 9 Review Questions

1. false
2. false
3. true
4. a
6. a
8. a
9. c

Chapter 9 Exercises

9.3

<html>
<head>
<title>Problem 9.3</title>
<script type="text/javascript">
function cheers() {
alert("Way to go!")
alert("Fantastic")
}

function encouragement() {
alert("Don't give up. You can do it!")
}

function displayAll() {
encouragement()
cheers()
}
</script>
</head>

<body>
<script tpe="text/javascript">
displayAll()
</script>
</body>
</html>

9.7

<html>
<head>
<title>Problem 9.7</title>
<script type="text/javascript">
function threeCheers(cheer1, cheer2, cheer3) {
alert(cheer1 + ", " + cheer2 + ", " + cheer3)
//If you leave out the ", " in the alert, then the alert will display "HipHipHooray"
}
</script>
</head>

<body>
<script type="text/javascript">
threeCheers("Hip", "Hip", "Hooray")
</script>
</body>
</html>

9.9

<html>
<head>
<title>Problem 9.9</title>
<script type="text/javascript">
function displayFullName(first, middle, last) {
alert("Your full name is: " + first + " " + middle + " " + last)
//If you leave out the ", " then the alert will display "HipHipHooray"
}
</script>
</head>

<body>
<script type="text/javascript">
var firstName, middleName, lastName
firstName = prompt("Please enter your first name: ", " ")
middleName = prompt("Please enter your middle name: ", " ")
lastName = prompt("Please enter your last name: ", " ")
displayFullName(firstName, middleName, lastName)
</script>
</body>
</html>

Powered by Io Community Manager