Question: Next, create the candidateRows() function. The purpose of this function is to write individual table rows for each candidate, showing the candidates name, party affiliation,
Next, create the candidateRows() function. The purpose of this function is to write individual table rows for each candidate, showing the candidates name, party affiliation, vote total, and vote percentage. The candidateRows() function has two parameters named raceNum and totalVotes. Place the commands in the following steps within this function. Declare a local variable named rowHTML that will contain the HTML code for the table row. Set the initial value of this variable to an empty text string. Create a for loop in which the counter variablej goes from 0 to 2 in steps of 1 unit. Within the for loop do the following: Declare a variable named candidateName that retrieves the name of the current candidate and the current race. (Hint : Retrieve the candidate name from the multidimensional candidate array using the reference, candidate[raceNum][j].) Declare a variable named candidateParty that retrieves the party affiliation of the current candidate in the current race from the multidimensional party array. Declare a variable named candidateVotes that retrieves the votes cast for the current candidate in the current race from the multidimensional votes array. Declare a variable named candidatePercent equal to the value returned by the calcPercent() function, calculating the percentage of votes received by the current candidate in the loop. Use candidateVotes as the first parameter value and totalVotes as the second parameter value. Add the following HTML code to the value of the rowHTML variable name ( party ) votes ( percent ) where name is the value of candidateName, party is the value of candidateParty, votes is the value of candidateVotes, and percent is the value of candidatePercent. Apply the toLocaleString() method to votes in order to display the vote total with a thousands separator. Apply the toFixed(1) method to percent in order to display percentage values to 1 decimal place. Return the value of the rowHTML variable.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
