## CSci 1001 Problem set 5. Due Thursday, April 16th.

You may work in pairs

### Problem 1 (8 points): determine the winner using a function

Write a JavaScript program to determine the winner of an election. The
page must have a form to enter names of two candidates and their
corresponding votes. When the button is clicked, display the winner
and the number of votes in the text area.

Below is the starting point
for the problem. Save it to a file and add the missing elements (the form
elements and the rest of the function). Note
that since the form gives you strings, not numbers, you need to use
`parseFloat`

as shown below to use the form data as
numbers.

```
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>
And the winner is...
</title>
<script type="text/javascript" language="javascript">
function determineTheWinner() {
v1 = parseFloat(document.theform.votes1.value);
// add the rest of the function here
}
</script>
</head>
<body>
<h1>And the winner is...</h1>
<p>Please enter names of two people and how many votes each person got.</p>
<p>
<form name="theform">
The first candidate:
<input type="text" name="first" size=10 value="Bart Simpson" /><br />
The first number of votes:
<input type="text" name="votes1" size=10 value="0" /><br />
<br />
<input type="button" value="Click me"
onClick="determineTheWinner();" />
<br />
<textarea name="winner" rows="2" cols="80" wrap="virtual"></textarea>
</form>
</p>
</body>
</html>
```

### Problem 2 (10 points)

Convert the following numbers from binary (base 2) to decimal (base
10). All numbers are positive.

- 10011
- 111
- 10100

Convert the following numbers from decimal to binary.

- 1
- 23
- 30

Convert the following numbers from hexadecimal (base 16) to decimal.

- A1
- 4B

Convert the following numbers from decimal to hexadecimal

- 88
- 139

### Problem 3 (8 points)

Exercises 18, 19, 20, 22 p. 229.

### How to submit

Send all of your program files to me by e-mail. You may submit the written
part (if any) in class or send it together with your problem set. Please send
only ONE e-mail with your entire submission, make sure you include
everything. Multiple e-mails with your homework may result in a lower
grade.

CSci 1001
course web site.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.