I just want this function to return an int back based on a string but its not working
It will be either H or V followed by 1 or 2 digits.
IE: H1 return 99
H09 return 91
H10 return 90
H50 return 50
V1 return 1
V05 return 5
V11 return 11
V50 return 50
spot will be my string thats going in.
get100YardVersionEugene: function(spot)
{
var team = spot.match(/[A-Z]+/);
var yard = spot.match(/([0-9]+)/);
if (team == "H")
{
return 100-yard;
}
else //V
{
return yard;
}
},
for some reason when its V9(or H9) it breaks but when i put in V09 it works.
Can someone tell me why?
EDIT: it breaks as in…
I have two variables start and end
so i have something like
start = get100YardVersionEugene(“V9”)
and I use start and end to draw it on html5 canvas
start = get100YardVersionEugene(“V9”) //doesn’t draw correctly
start = get100YardVersionEugene(“V09”) // draw correctly
You can simplify your regex a little so it only checks for
HorV.regarding the number, you need to remember that
matchreturns an Array, so you’ll need to get the value by index. Also, you shouldn’t need the capture group.And actually, you should really just use one regex.