Web Analytics Made Easy -
StatCounter Bowling Scorer - CodingForum

Announcement

Collapse
No announcement yet.

Bowling Scorer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bowling Scorer

    I need help with the code of this bowling scorer. I'm not that good at error checking, and I know you guys are good at it. Here's the code:

    Code:
    <html>
    <head><title>Bowling Scorer</title>
    <script type="text/javascript">
    var final_score = 0;
    function strike(roll){
    var strike_score = 10;
    if (document.a.board[roll+1].value=="X" || document.a.board[roll+1].value=="/" || document.a.board[roll+1].value=="\"){
     strike_score += 10;
     }
    else{
     strike_score += parseInt(document.a.board[roll+1].value);
     }
    if (document.a.board[roll+2].value=="X" || document.a.board[roll+2].value=="/" || document.a.board[roll+2].value=="\"){
     strike_score += 10;
     }
    else{
     strike_score += parseInt(document.a.board[roll+2].value);
     }
    return strike_score;
    }
    function spare(ro){
    var spare_score = 10;
    if (document.a.board[ro+1].value=="X" || document.a.board[ro+1].value=="/" || document.a.board[ro+1].value=="\"){
     spare_score += 10;
     }
    else{
     spare_score += parseInt(document.a.board[roll+1].value);
     }
    return spare_score;
    }
    function scoreit(){
    var rolls = new Array(21);
    for (x=0;x<document.a.board.length;x++){
     rolls[x] = document.a.board[x].value
     }
    for (y=0;y<rolls.length;y++){
     if (rolls[y]=="X"){
      final_score += strike(y);
      }
     else if (rolls[y]=="/" || rolls[y]=="\"){
      final_score += spare(y);
      final_score -= parseInt(rolls[y-1]);
      }
     else if (isNaN(parseInt(rolls[y]))){
      continue;
      }
     else{
      final_score += parseInt(rolls[y]);
      }
     }
    alert("You scored "+final_score+".");
    }
    </script>
    </head>
    <body>
    <form name="a">
    <table border>
    <tr>
    <th colspan=21>Bowling Scorer</th>
    </tr>
    <tr>
    <td colspan=2>1</td>
    <td colspan=2>2</td>
    <td colspan=2>3</td>
    <td colspan=2>4</td>
    <td colspan=2>5</td>
    <td colspan=2>6</td>
    <td colspan=2>7</td>
    <td colspan=2>8</td>
    <td colspan=2>9</td>
    <td colspan=3>10</td>
    </tr>
    <tr>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    <td><input type="text" maxlength=1 size=1 name="board"></td>
    </tr>
    <tr>
    <th colspan=21><input type="button" value="What's My Score" onclick="scoreit();"></th>
    </table>
    </form>
    </body>
    </html>
Working...
X