Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript generated table not working
    primarykey
    data
    text
    <p>Can anyone spot an obvious error? Why is this Javascript generated table (<code>showResults</code> function) not showing up in my html? This always happens when I have a lot of literal values to quote...I'd appreciate any other comments on my formatting (white-space) as well! </p> <pre><code> &lt;script type="text/javascript"&gt; //calculates sum of all values within an array function totalVotes(votes){ / var total=0; for (i=0;i&lt;votes.length;i++){ total = votes[i] + total; } return total; } //calculates a percentage, rounded to nearest integer function calcPercent(item, sum){ return Math.round((item/sum)*100); } //tests value of partyType parameter function createBar(partyType, percent){ switch (partyType){ case D: barText="&lt;td class='dem'&gt;&lt;/td&gt;"; break; case R: barText="&lt;td class='rep'&gt;&lt;/td&gt;"; break; case I: barText="&lt;td class='ind'&gt;&lt;/td&gt;"; break; case G: barText="&lt;td class='green'&gt;&lt;/td&gt;"; break; case L: barText="&lt;td class='lib'&gt;&lt;/td&gt;"; break; } for(i=1;i&lt;=percent;i++){ document.write(barText); } } function showResults(race,name,party,votes){ var totalV=function totalVotes(votes); document.write("&lt;h2&gt;" +race+ "&lt;/h2&gt;"); document.write("&lt;table cellspacing='0'&gt;"); document.write("&lt;tr&gt;"); document.write("&lt;th&gt;Candidate&lt;/th&gt;"); document.write("&lt;th class='num'&gt; Votes&lt;/th&gt;"); document.write("&lt;th class='num'&gt;%&lt;/th&gt;"); document.write("&lt;/tr&gt;"); for (r=0;r&lt;name.length;r++){ document.write("&lt;tr&gt;"); document.write("&lt;td&gt;"+name[i]+ '(' +party[r]+ ")" +"&lt;/td&gt;"); document.write("&lt;td class='num'&gt;" +votes[r]+ "&lt;/td&gt;"); var percent=function calPercent(votes[r],totalV) document.write("&lt;td class='num'&gt;(" +percent[r]+ "%)&lt;/td&gt;"); createBar(party[r], percent); document.write("&lt;/tr&gt;"); } document.write("&lt;/table&gt;"); } </code></pre> <p></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload