2530 loCM Website
Assignments
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>


Posted by senchent at 2005/06/29 08:10:58 PST
Edited at 2005/07/08 08:52:17 PST

Homework

  • Finish lab exercises for chapter 8.

  • Read chapter 9.

  • Do prelabs for chapter 9.

Prelab Answers


Chapter 8 Review Questions

3. c
7. b
9. a
11. a

Chapter 8 Exercises

8.6 In a <script> element, write the JavaScript code that uses the prompt() method to ask the user to enter the name of their favorite movie. The code should store the movie name in a variable named favoriteMovie. After the user enters the movie name and clicks the “OK” button, an alert box should appear with the message, “That’s mine, too.”

<script type="text/javascript">
var favoriteMovie
favoriteMovie = prompt("Enter the name of your favorite movie", " ")
alert("That's mine, too.")
</script>

8.10 (a) Write the line of JavaScript code that would call the alert() method and display the value of the document.URL property.
(b) Write the line of JavaScript code that would call the alert() method and display the values of the document.title and document.URL properties in one alert box, so that the whole message is on one line using the format:
“The title is [title is displayed here] and the URL is [URL goes here].”
(c) Show how to modify the code in (b) so that the second part of the sentence, starting with “and the URL is...” is displayed on a separate line in the alert box.

(a) alert(document.URL)
(b) alert("The title is " + document.title + "and the URL is " + document.URL)
(c) alert("The title is " + document.title + "\r and the URL is " + document.URL)


Posted by senchent at 2005/06/27 09:12:19 PST
Edited at 2005/06/29 08:10:01 PST

Homework

  • Read chapter 8.

  • Do prelabs for chapter 8.

  • Answer research project questions used in the example "Using Technology in the Classroom" (view the Research Project page).

  • If you have not done so already, be sure to have read chapter 2 in On the Internet (small book).

  • Lab exercises for chapter 7 can be completed at home or in the lab on Wednesday.

Prelab Answers

Chapter 7 Review Questions

4. sequence, selection (or conditional or branching or if/then), looping (or iteration), transfer (or go to or jump)
7. true
9. b and e
13. mouseover, onmouseover

Chapter 7 Exercises

7.1

(a) A runtime error is an error that occurs when the script or program is actually run (executed).
(b) An event handler is an attribute in certain HTML elements that is triggered when an event for that element occurs (e.g., an onclick event handler for a click button) and then activates certain specified JavaScript commands.
(c) An interpreter is a software program that takes the programmer’s source code and translates one line at a time into machine code and then executes the resulting machine code before moving on to the next high-level instruction to translate and execute.
(d) A script is a (relatively) small program that runs within the confines of an application.

7.2

1. Sequence: Following the instructions for assembling a toy, in proper order.
2. Conditional: Deciding whether to buy something based on its price (“If it’s less than $100, then I’ll buy it; otherwise, I won’t”).
3. Looping: Stapling, folding, and stamping a stack of newsletters for mailing. (Staple one, then fold it, then stamp it. Staple the next one, then fold it, then stamp it. And so on.)
4. Transfer: Switching from one task to another task, e.g., someone who’s working on a math homework problem decides that “at 2 pm I’ll stop working on it and jump to the next problem, even if I’m not done.”

7.6

<script type="text/javascript">
alert("Good to see you") //First of the three welcome messages
alert("Having a nice time?") //Second message
alert("See you later") //Third message
</script>

7.7

<form>
<input type="button" name="testBtn" value="Display an alert"
onclick="alert('This is just a test')" />
</form>

7.10

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www/w3/org/TR/xhtml/11/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Problem 7.10</title>
<script type="text/javascript">
alert("Message Number 1")
alert("Message Number 2")
</script>
</head>

<body>
<noscript>This page requires the use of a JavaScript-capable browser</noscript>
<script type="text/javascript">
alert("Message Number 3")
</script>
<form>
<input type="button" name="messageBtn" value="Click here!"
onclick="alert('Message Number 4')" />
</form>
</body>
</html>


Posted by senchent at 2005/06/24 12:00:58 PST
Edited at 2005/06/24 13:15:17 PST

Homework

  • Read chapter 7 (skip chapter 6)

  • Do the prelabs for chapter 7, finish lab exercises for chapter 5.

  • Read chapter 2 in your internet handbook (smaller book)

  • Make sure to bring in a paragraph describing your project if you have not done so already!

  • Also be sure to bring in any permission or emergency forms that you have not already turned in.

Prelab Answers

Chapter 5 Review Questions

3. d
7. a
8. c
10. c

Chapter 5 Exercises

5.1 Briefly explain the following terms: external link, internal link, index.html file.

(a) An external link is a link that, when clicked, takes the surfer from the currently displayed Web page to the beginning of another page.
(b) An internal link is a link that takes the surfer from one part of a Web page to another section in the same page.
(c) An index.html (or index.htm) file is the default name given to the introductory page of a Web site, so that when a Web server receives a request but the document isn’t specified, it responds by sending the index.html file from the appropriate directory (assuming it exists).

5.9 Write the HTML code that would create a “Back to top” link for a Web page. Assume that the first line displayed on the Web page is “Welcome to the Marine Mammals Page!”

<body>
<a name="topofpage">Welcome to the Marine Mammals Page!</a>
<!--Rest of page goes here...-->
<a href="#topofpage">Back to top</a>
</body>


Posted by senchent at 2005/06/22 20:02:56 PST
Edited at 2005/06/22 22:04:42 PST
Chapters 3+4

Homework

  • Read Chapter 5

  • Do the prelabs for Chapter 5

  • Make sure lab exercises up to chapter 4 are complete.

  • Bring in your project idea with at least a paragraph explaining it.


Prelab Answers

Chapter 3 Review Questions

1. b
3. c
4. d
6.

<style type="text/css">
p {text-indent:15pt}
</style>

8. true

Chapter 3 Exercises

3.6 Write the HTML code that would uses the font property to define a paragraph style with 16-point italic text and a 32-point line height.

<style type="text/css">
p {font: italic 16pt/32pt}
</style>

Note: See also the answer to 3.3 regarding the <head> and <meta> elements.

3.7 Write the HTML code that would define a paragraph class named “doublespace” that modified the regular paragraph style (however defined) to make it doublespaced. Also write the code for a sample paragraph of this class.

<style type="text/css">
p.doublespace {line-height:2}
</style>

Note: Alternatively, doublespacing may be specified as line-height:200%. See also the answer to 3.3 regarding the <head> and <meta> elements.

The code for a sample paragraph will be:

<p class="doublespace">Here is the text of the paragraph</p>

3.10 Write the HTML code that creates an external style sheet with style definitions for the code in Problems 3.6 and 3.7. Assuming that this style sheet has been saved in a file named teststyle.css, show how to write the HTML tag that you would place in the document where you wanted to apply the styles.

The code in the external style sheet file will be:

p {font: italic 16pt/32pt}
p.doublespace {line-height:2}

The tag to place in the source document will be:

<link rel="stylesheet" type="text/css" href="teststyle.css" />

Chapter 4 Review Questions

1. True
5. <!-- and -->
6. ordered and unordered
7. a
8. disc, square, and circle

Chapter 4 Exercises

4.2

Answer for styles:
<style type="text/css">
body {background-color:purple; color:white}
</style>

This <style> element would be placed in the <head> element.

Answer for attributes:
<body bgcolor="purple" text="white">
Web page text and elements go here...
</body>

4.4

<ul type="square">
<li>Item 1</li>
<li>Item 2</li>
<!-- <li>Item 3</li> -->
</ul>

4.7

<ol type="A">
<li>Major PC Manufacturers ca. 2000</li>
<ol type="1">
<li>Dell</li>
<li>IBM</li>
<li>Apple</li>
<li>Hewlett-Packard</li>
<li>Compaq</li>
</ol>
<li>Personal Computer Operating Systems ca. 2000
<ol type="1">
<li>Microsoft Windows (various flavors)</li>
<li>Mac OS</li>
<li>Linux</li>
</ol>
</ol>

4.10

<table cellspacing="5" cellpadding="3">
<tr>
<th colspan=3>Great Places to Eat</th> <!--This also could be a <tr> element, not <th> -->
</tr>
<tr>

<th>Restaurant</th>
<th>Type of Food</th>
<th>Personal Rating</th>

</tr>
<tr>

<td>Strings</td>
<td align="center">Italian</td>
<td>3 stars</td>

</tr>
<tr>

<td>Dos Coyotes</td>
<td align="center">Fresh Mex</td>
<td>4 stars</td>

</tr>
<tr>

<td>Symposium</td>
<td align="center">Greek</td>
<td>3 stars</td>

</tr>
<tr>

<td>The Graduate</td>
<td align="center">Burgers</td>
<td>2 stars</td>

</tr>
</table>

Powered by Io Community Manager