dasphatman
Programmer
I'm trying to create a golf score script, and are doing ok so far, but has stumbled on an issue.
To make this explanation easy I have decided to only use 3 holes in my score card.
The scorecard have 3 holes (hole1, hole2, hole3) which has a preferred number of strokes (par5, par4, par4). Now each hole has a difficult rating (hcp2, hcp3, hcp1) where one is the most difficult one. So each hole looks like this:
Hole1, Par5, Hcp2
Hole2, Par4, Hcp3
Hole3, Par4, Hcp1
Now a golf player has what is called a handicap depending on how good the player is. The lower handicap the better the player. The handicap is made so a player can use extra strokes on a hole to his round. Lets say a player has handicap 4.5 then the below formal is deciding how many extra strokes he has:
The maleslope, malerating and coursepar is normally from a mysql DB.
In this case the player has 5 extra strokes on the 3 holes.
Now for the tricky part!
These 5 extra strokes should be divided to the 3 holes in such a way that the easiest hole (hole2) should get 1 extra stroke while the 2 others should get 2 extra strokes, So what I want is to get a output like this, problary in a loop:
var stroke1 = 5 + 2
var stroke2 = 4 + 1
var stroke3 = 4 + 2
These vars I can then use in the last part of the script. I have stumbled over this script which does some of the thing, but I'm not that good at javascript, so I can't figure out how to get the output like above:
The script would be getting its hcp and par variables like this:
I hope somebody can help me getting the pieces together... Thanks alot
To make this explanation easy I have decided to only use 3 holes in my score card.
The scorecard have 3 holes (hole1, hole2, hole3) which has a preferred number of strokes (par5, par4, par4). Now each hole has a difficult rating (hcp2, hcp3, hcp1) where one is the most difficult one. So each hole looks like this:
Hole1, Par5, Hcp2
Hole2, Par4, Hcp3
Hole3, Par4, Hcp1
Now a golf player has what is called a handicap depending on how good the player is. The lower handicap the better the player. The handicap is made so a player can use extra strokes on a hole to his round. Lets say a player has handicap 4.5 then the below formal is deciding how many extra strokes he has:
Code:
<?php
$maleslope = '131';
$malerating = '71.7';
$coursepar = '72';
?>
var handicap = validNum(document.form1.handicapindex.value)
var strokes = handicap * <? echo $maleslope; ?> / 113 + <? echo $malerating; ?> - <? echo $coursepar; ?>;
newstroke = Math.round(strokes)
document.form1.strokecount.value = newstroke
The maleslope, malerating and coursepar is normally from a mysql DB.
In this case the player has 5 extra strokes on the 3 holes.
Now for the tricky part!
These 5 extra strokes should be divided to the 3 holes in such a way that the easiest hole (hole2) should get 1 extra stroke while the 2 others should get 2 extra strokes, So what I want is to get a output like this, problary in a loop:
var stroke1 = 5 + 2
var stroke2 = 4 + 1
var stroke3 = 4 + 2
These vars I can then use in the last part of the script. I have stumbled over this script which does some of the thing, but I'm not that good at javascript, so I can't figure out how to get the output like above:
Code:
var i=0, field=[0,1,2], number=document.form1.handicapindex.value;
while (number!==0)
{
field[i]+=1;
number-=1;
if (i===field.length-1) i=0
else i+=1;
}
The script would be getting its hcp and par variables like this:
Code:
<?php
$par1 = $row['par1'];
$par2 = $row['par2'];
$par3 = $row['par3'];
$hcp1 = $row['hcp1'];
$hcp2 = $row['hcp2'];
$hcp3 = $row['hcp3'];
?>
I hope somebody can help me getting the pieces together... Thanks alot