这里我拿了一个a NaN,如何检查/修复它?
let findAvareageOfWpm = Math.floor(wordsPerMinute/numberTrains)
它输出到屏幕上,我需要使如果findAvareageOfWpm的值是NaN,它应该返回0
j0pj023g1#
可以使用||(“逻辑或”)运算符:
||
let findAvareageOfWpm = Math.floor(wordsPerMinute/numberTrains) || 0;
Math.floor(wordsPerMinute/numberTrains) == NaN
findAvareageOfWpm
0
Math.floor(wordsPerMinute/numberTrains) == 0
findAvareageOfWpm = 0
findAvareageOfWpm = Math.floor(wordsPerMinute/numberTrains)
yhqotfr82#
if(!isNaN(每分钟字数)&&!isNaN(列车数)){设findWpm的平均值=数学楼层(每分钟字数/列车数)}
2条答案
按热度按时间j0pj023g1#
可以使用
||
(“逻辑或”)运算符:Math.floor(wordsPerMinute/numberTrains) == NaN
,则findAvareageOfWpm
将具有||
之后的任何值。在上面的示例中,它将是0
。Math.floor(wordsPerMinute/numberTrains) == 0
,那么findAvareageOfWpm = 0
也一样。findAvareageOfWpm = Math.floor(wordsPerMinute/numberTrains)
。yhqotfr82#
if(!isNaN(每分钟字数)&&!isNaN(列车数)){
设findWpm的平均值=数学楼层(每分钟字数/列车数)}