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.
Code:
window.SCORE_ROUND_DEFAULT = 11;
...
if(!isNaN(nmbr) && Number(nmbr) > 0) {
return nmbr;
} else {
return SCORE_ROUND_DEFAULT;
}
In fact, because any valid number will be greater than 0, you don't need the !isNaN part anymore.
Code:
if(Number(nmbr) > 0) {
return nmbr;
} else {
return SCORE_ROUND_DEFAULT;
}
So you can now condense that all down to a ternary operation:
Code javascript:
return (Number(nmbr) > 0) ? nmbr : SCORE_ROUND_DEFAULT;
Or, if you want to get tricksy...
Code javascript:
return Number(nmbr) || SCORE_ROUND_DEFAULT;
Resulting in a final function of:
Code javascript:
window.SCORE_ROUND_DEFAULT = 11;
function validNum(nmbr) {
return Number(nmbr) || SCORE_ROUND_DEFAULT;
}
Bookmarks