带有 json 的数组如何将 isNaN 转换为数字零,所以如果你使用数组 1,2,3 并减去 1,2 如何减去 1-1 2-2 3-NaN NaN 应该是 0 表示 3-0
// Create variables to append player's + or - score per hole
var golfStroke = scores[y].strokes[q];
var parStroke = pars[z];
var scoreStroke = parStroke - golfStroke;
// Create if statement to change undefined array values to number 0 for calculation
var isNum = function () {
if (isNaN(golfStroke)) {
return 0;
} else {
return golfStroke;
}
if (isNaN(parStroke)) {
return 0;
} else {
return parStroke;
};
}
console.log("The over or minus par is: " + scoreStroke);
谢谢