Writing Table Cells and Switch Statements
I am to create a function and purpose is to write blank tables cells to make up horizontal bar. function will have 2 parameters=(partyType and percent
partyType parameter stores variables of D,R,I,G or L
percent parameter store percentage rounded to nearest integer
so I am to make a switch and break statements /commands
then have to create a For Loop in counter variable goes up from 1 through value of parmeter increments of 1
heres the code I created for this one
Code:
function createBar(partyType,percent){ // script element to create blank cells
switch(partyType) {
case "D": document.write("<td class='dem'></td>");
break;
case "E": document.write("<td class='rep'></td>");
break;
case "I": document.write("<td class='ind'></td>");
break;
case "G": document.write("<td class='green'></td>");
break;
case "L": document.write("<td class='lib'></td>");
break;
}
var barText = partyType
for (i=0; i < percent; i++)
{
document.write(barText);
So what improvements should I make?
should my loop be before everything?
Thanks