I’m trying to make this golfscorecard script and it is working allmost correct…
It counts the numbers as it should and if a user inserts a nonnumeric value like “-” it counts that as 11. Great. But I also want to count “0” as 11 but not sure how to do so…
Here is my script:
// Makes sure variable is a number
function validNum(nmbr)
{
// forces variable into integer type
nmbr = (nmbr * 1);
// Checks if variable is Not a Number
if(!isNaN(nmbr))
// If a number, return value
return nmbr;
else
// If not a number, return eleven
return 11;
}
You don’t want a normal number to be returned when it’s 0, so you add that on as another condition. We can also replace 11 with a constant, so that there’s no mystery about what the value of 11 is supposed to mean.
The only problem with this is that when I change it to some of your examples it messes up the rest of the script… Whenb I type a number in the first field, the sum filed starts out with 90 something and it should sum the numbers I type…