Hi,
I am extremely new to JavaScript and am currently in a class. I am having big problems understanding the assignments from the book (it is the worst book ever and doesn’t even explain what to do in the assignments). I have scanned the assignment from the book and pasted the code in they give you. Any help doing this and understanding it would be greatly appreciated. Also what would be a great book to get to use to help me understand my horrible textbook?
Assignment pages: are attached they explain what you are supposed to do.
The files they supply:
election.htm:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
New Perspectives on JavaScript, 2nd Edition
Tutorial 3
Case Problem 2
Congressional Election Results
Author:
Date:
Filename: election.htm
Supporting files: back.jpg, logo.jpg, results.css, votes.js
-->
<title>Congressional Races</title>
<link href="results.css" rel="stylesheet" type="text/css" />
<script src="votes.js" type="text/javascript"></script>
<script type="text/javascript">
function totalVotes() {
var total = 0;
for (vari = 0; i < votes.length; i++) {
}
return total
}
</script>
</head>
<body>
<div id="intro">
<p><img src="logo.jpg" alt="Election Day Results" /></p>
<a href="#">Election Home Page</a>
<a href="#">President</a>
<a href="#">Senate Races</a>
<a href="#">Congressional Races</a>
<a href="#">State Senate</a>
<a href="#">State House</a>
<a href="#">Local Races</a>
<a href="#">Judicial</a>
<a href="#">Referendums</a>
</div>
<div id="results">
<h1>Congressional Races</h1>
</div>
</body>
</html>
votes.js:
/*
New Perspectives on JavaScript, 2nd Edition
Tutorial 3
Case Problem 2
Filename: votes.js
Variable List:
races: The name of the five races
name1 - name5: The name of the candidate for races 1 through 5
party1 - party5: The party affliations of the candidates
votes1 - votes5: The number of votes the candidate has received
*/
var race = new Array();
var name1 = new Array();
var name2 = new Array();
var name3 = new Array();
var name4 = new Array();
var name5 = new Array();
var party1 = new Array();
var party2 = new Array();
var party3 = new Array();
var party4 = new Array();
var party5 = new Array();
var votes1 = new Array();
var votes2 = new Array();
var votes3 = new Array();
var votes4 = new Array();
var votes5 = new Array();
race[0]="1st Congressional District";
race[1]="2nd Congressional District";
race[2]="3rd Congressional District";
race[3]="4th Congressional District";
race[4]="5th Congressional District";
name1[0]="Sarah Carlson";
party1[0]="D";
votes1[0]=45125;
name1[1]="Pete deJesus";
party1[1]="R";
votes1[1]=44498;
name1[2]="Alan Tompkins";
party1[2]="I";
votes1[2]=5143;
name2[0]="Gary Griffin";
party2[0]="D";
votes2[0]=69505;
name2[1]="Frank Brown";
party2[1]="R";
votes2[1]=78133;
name2[2]="Roland Washington";
party2[2]="G";
votes2[2]=8109;
name2[3]="Karen Reese";
party2[3]="L";
votes2[3]=13004;
name3[0]="Anne Sanchez";
party3[0]="D";
votes3[0]=65203;
name3[1]="Cynthia Thomas";
party3[1]="R";
votes3[1]=51289;
name4[0]="Jerry Wilkes";
party4[0]="D";
votes4[0]=49201;
name4[1]="Barry Mitchell";
party4[1]="R";
votes4[1]=58414;
name4[2]="Paula Welton";
party4[2]="I";
votes4[2]=3901;
name5[0]="Pete Grimbold";
party5[0]="D";
votes5[0]=42105;
name5[1]="Carol Ives";
party5[1]="R";
votes5[1]=43349;
name5[2]="Michael Dorn";
party5[2]="G";
votes5[2]=1401;