2013-04-23 40 views
0

好的,很抱歉,如果這是一個非常基本的功能,但我一直在爲一個十針保齡球評分系統做一個軟件,最後得到了評分系統工作的所有功能,但這只是對於一個玩家,我試圖複製函數給每個玩家一個函數(最多六個玩家)。正如我所說的代碼的一部分在那裏,但是當我嘗試複製函數和重命名變量等,它打破了代碼,任何幫助將不勝感激!在javascript中複製一個函數

<html> 
    <head> 
    <title>Bowling Score Calculator</title> 
    <script> 
    onebowl = new Array(21); 
    twobowl = new Array(21); 
    threebowl = new Array(21); 
    fourbowl = new Array(21); 
    fivebowl = new Array(21); 
    sixbowl = new Array(21); 
    score = new Array(11); 
    scoretwo = new Array(11); 
    scorethree = new Array(11); 
    scorefour = new Array(11); 
    scorefive = new Array(11); 
    scoresix = new Array(11); 

    function runScript() { 
    store(); 
    valid = verify(); 
    if(valid) {calculate();calculatetwo();print();}} 

    function store(){ 
    onebowl[0]=document.score.pl1bowl1.value; 
    onebowl[1]=document.score.pl1bowl2.value; 
    onebowl[2]=document.score.pl1bowl3.value; 
    onebowl[3]=document.score.pl1bowl4.value; 
    onebowl[4]=document.score.pl1bowl5.value; 
    onebowl[5]=document.score.pl1bowl6.value; 
    onebowl[6]=document.score.pl1bowl7.value; 
    onebowl[7]=document.score.pl1bowl8.value; 
    onebowl[8]=document.score.pl1bowl9.value; 
    onebowl[9]=document.score.pl1bowl10.value; 
    onebowl[10]=document.score.pl1bowl11.value; 
    onebowl[11]=document.score.pl1bowl12.value; 
    onebowl[12]=document.score.pl1bowl13.value; 
    onebowl[13]=document.score.pl1bowl14.value; 
    onebowl[14]=document.score.pl1bowl15.value; 
    onebowl[15]=document.score.pl1bowl16.value; 
    onebowl[16]=document.score.pl1bowl17.value; 
    onebowl[17]=document.score.pl1bowl18.value; 
    onebowl[18]=document.score.pl1bowl19.value; 
    onebowl[19]=document.score.pl1bowl20.value; 
    onebowl[20]=document.score.pl1bowl21.value; 

    twobowl[0]=document.score.pl2bowl1.value; 
    twobowl[1]=document.score.pl2bowl2.value; 
    twobowl[2]=document.score.pl2bowl3.value; 
twobowl[3]=document.score.pl2bowl4.value; 
twobowl[4]=document.score.pl2bowl5.value; 
twobowl[5]=document.score.pl2bowl6.value; 
twobowl[6]=document.score.pl2bowl7.value; 
twobowl[7]=document.score.pl2bowl8.value; 
twobowl[8]=document.score.pl2bowl9.value; 
twobowl[9]=document.score.pl2bowl10.value; 
twobowl[10]=document.score.pl2bowl11.value; 
twobowl[11]=document.score.pl2bowl12.value; 
twobowl[12]=document.score.pl2bowl13.value; 
twobowl[13]=document.score.pl2bowl14.value; 
twobowl[14]=document.score.pl2bowl15.value; 
twobowl[15]=document.score.pl2bowl16.value; 
twobowl[16]=document.score.pl2bowl17.value; 
twobowl[17]=document.score.pl2bowl18.value; 
twobowl[18]=document.score.pl2bowl19.value; 
twobowl[19]=document.score.pl2bowl20.value; 
twobowl[20]=document.score.pl2bowl21.value; 

threebowl[0]=document.score.pl3bowl1.value; 
threebowl[1]=document.score.pl3bowl2.value; 
threebowl[2]=document.score.pl3bowl3.value; 
threebowl[3]=document.score.pl3bowl4.value; 
threebowl[4]=document.score.pl3bowl5.value; 
threebowl[5]=document.score.pl3bowl6.value; 
threebowl[6]=document.score.pl3bowl7.value; 
threebowl[7]=document.score.pl3bowl8.value; 
threebowl[8]=document.score.pl3bowl9.value; 
threebowl[9]=document.score.pl3bowl10.value; 
threebowl[10]=document.score.pl3bowl11.value; 
threebowl[11]=document.score.pl3bowl12.value; 
threebowl[12]=document.score.pl3bowl13.value; 
threebowl[13]=document.score.pl3bowl14.value; 
threebowl[14]=document.score.pl3bowl15.value; 
threebowl[15]=document.score.pl3bowl16.value; 
threebowl[16]=document.score.pl3bowl17.value; 
threebowl[17]=document.score.pl3bowl18.value; 
threebowl[18]=document.score.pl3bowl19.value; 
threebowl[19]=document.score.pl3bowl20.value; 
threebowl[20]=document.score.pl3bowl21.value; 

fourbowl[0]=document.score.pl4bowl1.value; 
fourbowl[1]=document.score.pl4bowl2.value; 
fourbowl[2]=document.score.pl4bowl3.value; 
fourbowl[3]=document.score.pl4bowl4.value; 
fourbowl[4]=document.score.pl4bowl5.value; 
fourbowl[5]=document.score.pl4bowl6.value; 
fourbowl[6]=document.score.pl4bowl7.value; 
fourbowl[7]=document.score.pl4bowl8.value; 
fourbowl[8]=document.score.pl4bowl9.value; 
fourbowl[9]=document.score.pl4bowl10.value; 
fourbowl[10]=document.score.pl4bowl11.value; 
fourbowl[11]=document.score.pl4bowl12.value; 
fourbowl[12]=document.score.pl4bowl13.value; 
fourbowl[13]=document.score.pl4bowl14.value; 
fourbowl[14]=document.score.pl4bowl15.value; 
fourbowl[15]=document.score.pl4bowl16.value; 
fourbowl[16]=document.score.pl4bowl17.value; 
fourbowl[17]=document.score.pl4bowl18.value; 
fourbowl[18]=document.score.pl4bowl19.value; 
fourbowl[19]=document.score.pl4bowl20.value; 
fourbowl[20]=document.score.pl4bowl21.value; 

fivebowl[0]=document.score.pl5bowl1.value; 
fivebowl[1]=document.score.pl5bowl2.value; 
fivebowl[2]=document.score.pl5bowl3.value; 
fivebowl[3]=document.score.pl5bowl4.value; 
fivebowl[4]=document.score.pl5bowl5.value; 
fivebowl[5]=document.score.pl5bowl6.value; 
fivebowl[6]=document.score.pl5bowl7.value; 
fivebowl[7]=document.score.pl5bowl8.value; 
fivebowl[8]=document.score.pl5bowl9.value; 
fivebowl[9]=document.score.pl5bowl10.value; 
fivebowl[10]=document.score.pl5bowl11.value; 
fivebowl[11]=document.score.pl5bowl12.value; 
fivebowl[12]=document.score.pl5bowl13.value; 
fivebowl[13]=document.score.pl5bowl14.value; 
fivebowl[14]=document.score.pl5bowl15.value; 
fivebowl[15]=document.score.pl5bowl16.value; 
fivebowl[16]=document.score.pl5bowl17.value; 
fivebowl[17]=document.score.pl5bowl18.value; 
fivebowl[18]=document.score.pl5bowl19.value; 
fivebowl[19]=document.score.pl5bowl20.value; 
fivebowl[20]=document.score.pl5bowl21.value; 

sixbowl[0]=document.score.pl6bowl1.value; 
sixbowl[1]=document.score.pl6bowl2.value; 
sixbowl[2]=document.score.pl6bowl3.value; 
sixbowl[3]=document.score.pl6bowl4.value; 
sixbowl[4]=document.score.pl6bowl5.value; 
sixbowl[5]=document.score.pl6bowl6.value; 
sixbowl[6]=document.score.pl6bowl7.value; 
sixbowl[7]=document.score.pl6bowl8.value; 
sixbowl[8]=document.score.pl6bowl9.value; 
sixbowl[9]=document.score.pl6bowl10.value; 
sixbowl[10]=document.score.pl6bowl11.value; 
sixbowl[11]=document.score.pl6bowl12.value; 
sixbowl[12]=document.score.pl6bowl13.value; 
sixbowl[13]=document.score.pl6bowl14.value; 
sixbowl[14]=document.score.pl6bowl15.value; 
sixbowl[15]=document.score.pl6bowl16.value; 
sixbowl[16]=document.score.pl6bowl17.value; 
sixbowl[17]=document.score.pl6bowl18.value; 
sixbowl[18]=document.score.pl6bowl19.value; 
sixbowl[19]=document.score.pl6bowl20.value; 
sixbowl[20]=document.score.pl6bowl21.value; 
} 

function verify(){ 
//for first 9 frames 
for(i=0;i<=17;i+=2){ 
switch(onebowl[i]){//first bowl of frame 
case 'x':case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9':break; 
default: alert("Please enter a valid number! Make sure the total for each frame is not above 9, if a spare is scored please enter '/'");return false;} 

switch(onebowl[i+1]){//second bowl of frame 
case '/': if(onebowl[i] < '0' || onebowl[i] > '9'){alert("Invalid");return false;} 
case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9': if(parseInt(onebowl[i]) + parseInt(onebowl[i+1]) >9){alert("Invalid");return false;}break; 
default: if(onebowl[i] != 'x'){alert("Invalid");return false;}} 
} 

//for tenth frame 
switch(onebowl[18]){//first bowl 
case 'x':case '0':case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9':break; 
default: alert("Invalid");return false;} 

switch(onebowl[19]){//second bowl 
case 'x':if(onebowl[18] != 'x'){alert("Invalid");return false;}break; 
case '/':if(onebowl[18] < '0' || onebowl[18] > '9'){alert("Invalid");return false;}break; 
case '0':case'1':case'2':case'3':case'4':case'5':case'6':case'7':case'8':case'9': 
if(onebowl[18] != 'x'){if(parseInt(onebowl[18])+parseInt(onebowl[19])>9){alert("Invalid");return false;}}break; 
default:alert("Invalid");return false;} 

if(onebowl[18] != 'x' && onebowl[19] != '/')return true; 

switch(onebowl[20]){//third bowl 
case 'x':if(onebowl[19] != 'x' && onebowl[19] != '/'){alert("Invalid");return false;}break; 
case '/':if(onebowl[19] < '0' || onebowl[19] > '9'){alert("Invalid");return false;}break; 
case '0':case'1':case'2':case'3':case'4':case'5':case'6':case'7':case'8':case'9': 
if(onebowl[19] != 'x' && onebowl[19] != '/'){if(parseInt(onebowl[18])+parseInt(onebowl[19])>9){alert("Invalid");return false;}}break; 
default:alert("Invalid");return false;} 

return true;} 

function calculate(){ 
frame = 0; 
lastFrame = 0; 
for(i=0;i<8;i++){//first 8 frames 
if (onebowl[2*i] == 'x'){//strike this frame 
    if ((onebowl[2*i+2] == 'x') && (onebowl[2*i+4] == 'x')) //strike on next 2 bowls 
     score[i] = lastFrame + 30; 
    else if (onebowl[2*i+2] == 'x') //one more strike after this 
     score[i] = lastFrame + 20 + parseInt(onebowl[2*i+4]); 
    else if (onebowl[2*i+3] == '/') //strike followed by a spare 
     score[i] = lastFrame + 20; 
    else //strike followed by an open 
     score[i] = lastFrame + 10 + parseInt(onebowl[2*i+2]) + parseInt(onebowl[2*i+3]);} 

else if (onebowl[2*i+1] == '/'){ //spare this frame 
    if (onebowl[2*i+2] == 'x') //next bowl is a strike 
     score[i] = lastFrame + 20; 
    else //next bowl not a strike 
     score[i] = lastFrame + 10 + parseInt(onebowl[2*i+2]);} 

else //open this frame 
    score[i] = lastFrame + parseInt(onebowl[2*i])+parseInt(onebowl[2*i+1]); 
lastFrame = score[i]; 
} 
//9th frame 
if (onebowl[16] == 'x'){//strike this frame 
    if ((onebowl[18] == 'x') && (onebowl[19] == 'x'))//followed by 2 strikes in tenth 
     score[8] = lastFrame + 30; 
    else if (onebowl[18] == 'x')//followed by 1 strike in the tenth 
     score[8] = lastFrame + 20 + parseInt(onebowl[19]); 
    else if (onebowl[19] == '/')//followed by a spare in the tenth 
     score[8] = lastFrame + 20; 
    else//followed by an open in the tenth 
     score[8] = lastFrame + 10 + parseInt(onebowl[18])+parseInt(onebowl[19]);} 

else if (onebowl[17] == '/'){//spare this frame 
    if (onebowl[18] == 'x')//followed by a strike in tenth 
     score[8] = lastFrame + 20; 
    else//followed by something else 
     score[8] = lastFrame + 10 + parseInt(onebowl[18]);} 

else //open this frame 
    score[8] = lastFrame + parseInt(onebowl[16]) + parseInt(onebowl[17]); 
lastFrame = score[8]; 
//10th frame 
if (onebowl[18] == 'x'){ //first bowl is a strike 
    if ((onebowl[19] == 'x') && (onebowl[20] == 'x'))//3 strikes in the tenth 
     score[9] = lastFrame + 30; 
    else if (onebowl[19] == 'x')//first 2 are strikes 
     score[9] = lastFrame + 20 + parseInt(onebowl[20]); 
    else if (bowl[20] == '/')//one strike followed by a spare 
     score[9] = lastFrame + 20; 
    else//one strike followed by an open 
     score[9] = lastFrame + 10 + parseInt(onebowl[19]) + parseInt(onebowl[20]);} 

else if (onebowl[19] == '/'){ //first bowl is a spare 
    if (onebowl[20] == 'x') //spare followed by a strike 
     score[9] = lastFrame + 20; 
    else//spare followed by an open 
     score[9] = lastFrame + 10 + parseInt(onebowl[20]);} 

else //open in the tenth 
    score[9] = lastFrame + parseInt(onebowl[18]) + parseInt(onebowl[19]); 
} 


function print(){ 
player1score1.innerHTML =""; 
player1score1.innerHTML += "" + score[0]; 
player1score2.innerHTML =""; 
player1score2.innerHTML += "" + score[1]; 
player1score3.innerHTML =""; 
player1score3.innerHTML += "" + score[2]; 
player1score4.innerHTML =""; 
player1score4.innerHTML += "" + score[3]; 
player1score5.innerHTML =""; 
player1score5.innerHTML += "" + score[4]; 
player1score6.innerHTML =""; 
player1score6.innerHTML += "" + score[5]; 
player1score7.innerHTML =""; 
player1score7.innerHTML += "" + score[6]; 
player1score8.innerHTML =""; 
player1score8.innerHTML += "" + score[7]; 
player1score9.innerHTML =""; 
player1score9.innerHTML += "" + score[8]; 
player1score10.innerHTML =""; 
player1score10.innerHTML += "" + score[9]; 
player2score1.innerHTML =""; 
player2score1.innerHTML += "" + scoretwo[0]; 
player2score2.innerHTML =""; 
player2score2.innerHTML += "" + scoretwo[1]; 
player2score3.innerHTML =""; 
player2score3.innerHTML += "" + scoretwo[2]; 
player2score4.innerHTML =""; 
player2score4.innerHTML += "" + scoretwo[3]; 
player2score5.innerHTML =""; 
player2score5.innerHTML += "" + scoretwo[4]; 
player2score6.innerHTML =""; 
player2score6.innerHTML += "" + scoretwo[5]; 
player2score7.innerHTML =""; 
player2score7.innerHTML += "" + scoretwo[6]; 
player2score8.innerHTML =""; 
player2score8.innerHTML += "" + scoretwo[7]; 
player2score9.innerHTML =""; 
player2score9.innerHTML += "" + scoretwo[8]; 
player2score10.innerHTML =""; 
player2score10.innerHTML += "" + scoretwo[9]; 
player3score1.innerHTML =""; 
player3score1.innerHTML += "" + scorethree[0]; 
player3score2.innerHTML =""; 
player3score2.innerHTML += "" + scorethree[1]; 
player3score3.innerHTML =""; 
player3score3.innerHTML += "" + scorethree[2]; 
player3score4.innerHTML =""; 
player3score4.innerHTML += "" + scorethree[3]; 
player3score5.innerHTML =""; 
player3score5.innerHTML += "" + scorethree[4]; 
player3score6.innerHTML =""; 
player3score6.innerHTML += "" + scorethree[5]; 
player3score7.innerHTML =""; 
player3score7.innerHTML += "" + scorethree[6]; 
player3score8.innerHTML =""; 
player3score8.innerHTML += "" + scorethree[7]; 
player3score9.innerHTML =""; 
player3score9.innerHTML += "" + scorethree[8]; 
player3score10.innerHTML =""; 
player3score10.innerHTML += "" + scorethree[9]; 
player4score1.innerHTML =""; 
player4score1.innerHTML += "" + scorefour[0]; 
player4score2.innerHTML =""; 
player4score2.innerHTML += "" + scorefour[1]; 
player4score3.innerHTML =""; 
player4score3.innerHTML += "" + scorefour[2]; 
player4score4.innerHTML =""; 
player4score4.innerHTML += "" + scorefour[3]; 
player4score5.innerHTML =""; 
player4score5.innerHTML += "" + scorefour[4]; 
player4score6.innerHTML =""; 
player4score6.innerHTML += "" + scorefour[5]; 
player4score7.innerHTML =""; 
player4score7.innerHTML += "" + scorefour[6]; 
player4score8.innerHTML =""; 
player4score8.innerHTML += "" + scorefour[7]; 
player4score9.innerHTML =""; 
player4score9.innerHTML += "" + scorefour[8]; 
player4score10.innerHTML =""; 
player4score10.innerHTML += "" + scorefour[9]; 
player5score1.innerHTML =""; 
player5score1.innerHTML += "" + scorefive[0]; 
player5score2.innerHTML =""; 
player5score2.innerHTML += "" + scorefive[1]; 
player5score3.innerHTML =""; 
player5score3.innerHTML += "" + scorefive[2]; 
player5score4.innerHTML =""; 
player5score4.innerHTML += "" + scorefive[3]; 
player5score5.innerHTML =""; 
player5score5.innerHTML += "" + scorefive[4]; 
player5score6.innerHTML =""; 
player5score6.innerHTML += "" + scorefive[5]; 
player5score7.innerHTML =""; 
player5score7.innerHTML += "" + scorefive[6]; 
player5score8.innerHTML =""; 
player5score8.innerHTML += "" + scorefive[7]; 
player5score9.innerHTML =""; 
player5score9.innerHTML += "" + scorefive[8]; 
player5score10.innerHTML =""; 
player5score10.innerHTML += "" + scorefive[9]; 
player6score1.innerHTML =""; 
player6score1.innerHTML += "" + scoresix[0]; 
player6score2.innerHTML =""; 
player6score2.innerHTML += "" + scoresix[1]; 
player6score3.innerHTML =""; 
player6score3.innerHTML += "" + scoresix[2]; 
player6score4.innerHTML =""; 
player6score4.innerHTML += "" + scoresix[3]; 
player6score5.innerHTML =""; 
player6score5.innerHTML += "" + scoresix[4]; 
player6score6.innerHTML =""; 
player6score6.innerHTML += "" + scoresix[5]; 
player6score7.innerHTML =""; 
player6score7.innerHTML += "" + scoresix[6]; 
player6score8.innerHTML =""; 
player6score8.innerHTML += "" + scoresix[7]; 
player6score9.innerHTML =""; 
player6score9.innerHTML += "" + scoresix[8]; 
player6score10.innerHTML =""; 
player6score10.innerHTML += "" + scoresix[9]; 
} 

</script> 
</head> 

<body bgcolor="#ffffff"> 
    <center><img src="http://www.dr-designs.co.uk/bowlarama.png"></center> 

<form name="score"> 
&nbsp;<center> 
<table border="0" cellspacing="1" width="100%" id="AutoNumber1" height="45"> 
    <tr> 
    <td width="7%" height="19" bgcolor="transparent"><font color="#000000"><b>Frame</b></font></td> 
    <td width="7%" height="19" bgcolor="transparent" align="center"><font color="#000000"><b>1</b></font></td> 
    <td width="7%" height="19" bgcolor="transparent" align="center"><font color="#000000"><b>2</b></font></td> 
    <td width="7%" height="19" bgcolor="transparent" align="center"><font color="#000000"><b>3</b></font></td> 
    <td width="7%" height="19" bgcolor="transparent" align="center"><font color="#000000"><b>4</b></font></td> 
    <td width="7%" height="19" bgcolor="transparent" align="center"><font color="#000000"><b>5</b></font></td> 
    <td width="7%" height="19" bgcolor="transparent" align="center"><font color="#000000"><b>6</b></font></td> 
    <td width="7%" height="19" bgcolor="transparent" align="center"><font color="#000000"><b>7</b></font></td> 
    <td width="7%" height="19" bgcolor="transparent" align="center"><font color="#000000"><b>8</b></font></td> 
    <td width="7%" height="19" bgcolor="transparent" align="center"><font color="#000000"><b>9</b></font></td> 
    <td width="7%" height="19" bgcolor="transparent" align="center"><font color="#000000"><b>10</b></font></td> 
    </tr> 
    <tr><!--This is the form for the 1st player--> 
    <td id="player1name" width="7%" height="16" bgcolor="transparent"><font color="#000000"><b>Score</b></font></td> 
    <td id="player1score1" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl1bowl1"> 
     <input type=text maxlength=1 size=1 name="pl1bowl2"> 
    </td> 
    <td id="player1score2" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl1bowl3"> 
     <input type=text maxlength=1 size=1 name="pl1bowl4"> 
    </td> 
    <td id="player1score3" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl1bowl5"> 
     <input type=text maxlength=1 size=1 name="pl1bowl6"> 
    </td> 
    <td id="player1score4" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl1bowl7"> 
     <input type=text maxlength=1 size=1 name="pl1bowl8"> 
    </td> 
    <td id="player1score5" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl1bowl9"> 
     <input type=text maxlength=1 size=1 name="pl1bowl10"> 
    </td> 
    <td id="player1score6" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl1bowl11"> 
     <input type=text maxlength=1 size=1 name="pl1bowl12"> 
    </td> 
    <td id="player1score7" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl1bowl13"> 
     <input type=text maxlength=1 size=1 name="pl1bowl14"> 
    </td> 
    <td id="player1score8" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl1bowl15"> 
     <input type=text maxlength=1 size=1 name="pl1bowl16"> 
    </td> 
    <td id="player1score9" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl1bowl17"> 
     <input type=text maxlength=1 size=1 name="pl1bowl18"> 
    </td> 
    <td id="player1score10" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl1bowl19"> 
     <input type=text maxlength=1 size=1 name="pl1bowl20"> 
     <input type=text maxlength=1 size=1 name="pl1bowl21"> 
    </td> 
    </tr> 
    <tr><!--This is the form for the 2nd player--> 
    <td id="player2name" width="7%" height="16" bgcolor="transparent"><font color="#000000"><b>Score</b></font></td> 
    <td id="player2score1" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl2bowl1"> 
     <input type=text maxlength=1 size=1 name="pl2bowl2"> 
    </td> 
    <td id="player2score2" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl2bowl3"> 
     <input type=text maxlength=1 size=1 name="pl2bowl4"> 
    </td> 
    <td id="player2score3" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl2bowl5"> 
     <input type=text maxlength=1 size=1 name="pl2bowl6"> 
    </td> 
    <td id="player2score4" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl2bowl7"> 
     <input type=text maxlength=1 size=1 name="pl2bowl8"> 
    </td> 
    <td id="player2score5" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl2bowl9"> 
     <input type=text maxlength=1 size=1 name="pl2bowl10"> 
    </td> 
    <td id="player2score6" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl2bowl11"> 
     <input type=text maxlength=1 size=1 name="pl2bowl12"> 
    </td> 
    <td id="player2score7" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl2bowl13"> 
     <input type=text maxlength=1 size=1 name="pl2bowl14"> 
    </td> 
    <td id="player2score8" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl2bowl15"> 
     <input type=text maxlength=1 size=1 name="pl2bowl16"> 
    </td> 
    <td id="player2score9" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl2bowl17"> 
     <input type=text maxlength=1 size=1 name="pl2bowl18"> 
    </td> 
    <td id="player2score10" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl2bowl19"> 
     <input type=text maxlength=1 size=1 name="pl2bowl20"> 
     <input type=text maxlength=1 size=1 name="pl2bowl21"> 
    </td> 
    </tr> 
    <tr><!--This is the form for the 3rd player--> 
    <td id="player3name" width="7%" height="16" bgcolor="transparent"><font color="#000000"><b>Score</b></font></td> 
    <td id="player3score1" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl3bowl1"> 
     <input type=text maxlength=1 size=1 name="pl3bowl2"> 
    </td> 
    <td id="player3score2" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl3bowl3"> 
     <input type=text maxlength=1 size=1 name="pl3bowl4"> 
    </td> 
    <td id="player3score3" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl3bowl5"> 
     <input type=text maxlength=1 size=1 name="pl3bowl6"> 
    </td> 
    <td id="player3score4" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl3bowl7"> 
     <input type=text maxlength=1 size=1 name="pl3bowl8"> 
    </td> 
    <td id="player3score5" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl3bowl9"> 
     <input type=text maxlength=1 size=1 name="pl3bowl10"> 
    </td> 
    <td id="player3score6" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl3bowl11"> 
     <input type=text maxlength=1 size=1 name="pl3bowl12"> 
    </td> 
    <td id="player3score7" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl3bowl13"> 
     <input type=text maxlength=1 size=1 name="pl3bowl14"> 
    </td> 
    <td id="player3score8" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl3bowl15"> 
     <input type=text maxlength=1 size=1 name="pl3bowl16"> 
    </td> 
    <td id="player3score9" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl3bowl17"> 
     <input type=text maxlength=1 size=1 name="pl3bowl18"> 
    </td> 
    <td id="player3score10" width="7%" height="16" bgcolor="transparent" align="center"> 
     <input type=text maxlength=1 size=1 name="pl3bowl19"> 
     <input type=text maxlength=1 size=1 name="pl3bowl20"> 
     <input type=text maxlength=1 size=1 name="pl3bowl21"> 
    </td> 
    </tr> 



</table> 
<p><input type=button value="Calculate Score" onclick="runScript();"> 

    </center> 
    </form> 
    <hr> 
</body> 
</html> 
+0

不得不刪除第4,第5和第6個球員的表格代碼,但是這些與以前的球員相同(變量的格式相同)另外我知道它可能不是最好的代碼,這個是我第一次嘗試JavaScript,所以我在學習,我只是需要一些我理解的東西,並且可以解釋它如何在面板上進行評估! – Danny 2013-04-23 19:09:37

+0

也剛剛意識到,我沒有解釋軟件的功能,玩家輸入他們的分數,然後當他們按下提交按鈕時,它會計算分數並將他們顯示在與他們輸入分數相同的盒子裏的電子賀卡。 – Danny 2013-04-23 19:11:45

+1

電腦非常棒執行世俗,重複的任務。編程語言有能力告訴計算機做重複的事情。如果你發現自己重複相同或非常相似的東西,那麼你正在做計算機應該做的工作。 – 2013-04-23 19:18:41

回答

2

歡迎的概念,即

複製和粘貼代碼是一切罪惡的根源

我的回答是,回到你有它的工作,單用戶的方式,重構,所以你可以用重用這個代碼以通用的方式。您可以將您的解決方案發布給1名玩家以獲得設計建議。

即使你能像這樣工作,你也不想。這是不行的。

+0

當然,如果它完全相同的工作,那麼複製你已經完善的代碼是有意義的?它對於一個玩家來說非常適合我只需要爲其他5的相同的功能,當然不是'複用'的代碼相同,複製和粘貼它,然後改變變量? – Danny 2013-04-23 19:17:18

+2

好神啊...... NO。你認爲谷歌複製和粘貼每個代碼他們是我們數百萬人之一ERS? – hvgotcodes 2013-04-23 19:18:23

+0

我離Google很遠,就像前面提到的那樣,這是我第一次用javascript編碼,只是尋找一個指向簡單解決方案的指針,使其具有功能性,不必是漂亮的或者是「正確的」方式只是功能 – Danny 2013-04-23 19:22:33

相關問題