VW Results - Js ASF
VW Results - Js ASF
/*
Tutorial 10
Case Problem 4
1. Use your editor to open the
vw_election_txt.html and
vw_results_txt.js files from the
Author: Pam Carls html10 c case4 folder. Enter your
name and the date in the comment
Date: 2018-03-01 section of each file, and save them as
vw_election.html and vw_results.js
respectively
Filename: vw_results.js
Functions:
*/
reportHTML += "<tr><th>Candidate</th><th>Votes</th></tr>";
rowHTML += "<tr>";
return rowHTML;
function calcSum(value) {
totalVotes += value;
}
return (100*value/sum);
10. Pam also wants the report to
} display the vote percentages as bar
charts with the length of the bar
corresponding to the percentage
value. Return to the vw_results.js file
/* Function to create a bar chart for different candidate vote percentages */ in your editor. At the bottom of the
file, create a function named
function createBar(partyType) { createBar() with one parameter
named partyType. Add the
/* Write a table cell for each percentage point */ commands described in Steps a
through b to the function:
var barHTML = ""; a. Declare a variable named barHTML
and set its initial value to an empty
switch (partyType) { text string. Explore b. Create a
switch/case statement that tests the
case "D": barHTML="<td class='dem'></td>";break; value of the partyType parameter. If
partyType equal "D" set barHTML
case "R": barHTML="<td class='rep'></td>";break; equal to: <td class='dem'></td> If
partyType equals "R" set barHTML
case "I": barHTML="<td class='ind'></td>";break; equal to: <td class='rep'></td> Finally,
if partyType equals "I" set barHTML
} to: <td class='ind'></td>
return barHTML;
11. Return the value of barHTML.
Next, add these empty data cells to
}
the race results table, with one cell
for every percentage point cast for
the candidate
13. Add comments throughout the
file with descriptive information
about the variables and functions