Question 1

 

The following HTML file:

 

<html>

<head>

<script>

</script>

</head>

<body>

<form name="form1">

Extra Credit

<input type="checkbox" name="extra" onClick="grade()">

<br>Number Right<select name="correct" onChange="grade()">

  <option value="4"> 4 </option>

  <option value="3"> 3 </option>

  <option value="2"> 2 </option>

  <option value="1"> 1 </option>

  <option value="0" selected> 0 </option>

</select>

<br>Score<input type="text" name="score" value="0">

</form>

</body>

</html>

 

Looks like this:

 

 


Write the code for the grade() function so that the person’s score is the number right times 25. And if they did the extra credit, they get 10 extra points.

 

 

 


Question 2

 

The following HTML file:

 

<html>

<head>

<script>

</script>

</head>

<body>

<form name="form1">

Extra Credit <input type="checkbox" name="extra">

<br>Number Right<select name="correct">

  <option value="4"> 4 </option>

  <option value="3"> 3 </option>

  <option value="2"> 2 </option>

  <option value="1"> 1 </option>

  <option value="0" selected> 0 </option>

</select>

<br>Score<input type="text" name="score">

<br><input type="button" value="Get Results"

           onClick="getResults()">

</form>

</body>

</html>

 

Looks like this:

 


Write the code for the getResults() function. It should produce output in a new window that looks like this:

 

 

It should print the number right.

 

If the score is at least 65, “You Pass!” is printed in green. Otherwise, “You Fail” is printed in red.

 

 


Question 3:

 

The following HTML file:

 

<html>

<head>

<script>

function getObj(elementID)

{

  return document.getElementById(elementID);

}

</script>

<style type="text/css">

#box {height:100; width:300; border-width:3;

      border-style:dotted}

</style>

</head>

<body onLoad="animate()">

<div id="box">

Welcome to exam 2. All of this test comes from notes and homeworks. This question requires you to put together two things you already did.

</div>

</body>

</html>

 

 Looks like this:

 

 


Write the code for the  animate() function. It should cause the borderStyle of the box to alternate between dotted and solid, at an interval of 100 milliseconds.

 

If you need to use global variables also, that’s fine.

 

 


Question 4

 

The following HTML file:

 

<html>

<head>

<script>

function getObj(elementID)

{

  return document.getElementById(elementID);

}

</script>

<style type="text/css">

#box {height:150; width:400; border-width:3; border-style:dotted; overflow:scroll}

#homer {position:absolute; top:10; left:500}

</style>

</head>

<body>

<div id="box">

</div>

<img id="homer" src="homer.jpg" onClick="hit()">

</body>

</html>

 

Looks like this:

 


Write code for the hit() function so that every time the user clicks on the picture of Homer Simpson to the right of the box, a new image of Homer Simpson appears inside the box.

 

 

It’s OK if your code works for either Mozilla Firefox or for Internet Explorer; but you’ll get extra credit if it works for both.