Javascript 改进if语句链

Javascript 改进if语句链,javascript,Javascript,此处NewCPC需要一个数字。因此,firstPositionCpc、topOfPageCpc和firstPageCpc需要存在并且是一个数字 KeywordIdReport :197857118477 campaignName :BP 2015 QC (FR) maxCPC : 3.00 OldCPC :0.46 firstPositionCpc : -- topOfPageCpc : 0.46 firstPageCpc : 0.05 NewCPC : -- 此处NewCPC需要小于或等于m

此处
NewCPC
需要一个数字。因此,
firstPositionCpc
topOfPageCpc
firstPageCpc
需要存在并且是一个数字

KeywordIdReport :197857118477
campaignName :BP 2015 QC (FR)
maxCPC : 3.00
OldCPC :0.46
firstPositionCpc : --
topOfPageCpc : 0.46
firstPageCpc : 0.05
NewCPC : --
此处
NewCPC
需要小于或等于
maxCPC
。通常,对于
NewCPC
,答案应该是
1.68
,而不是
4.28

我如何修复if语句链,使其能够修复错误的场景

更新 现在经过改进,我怎么能说
firstPositionCpc
topOfPageCpc
firstPageCpc
的类型存在并且需要是一个数字呢

因此,firstPositionCpc、topOfPageCpc和firstPageCpc需要存在并成为一个数字

KeywordIdReport :197857118477
campaignName :BP 2015 QC (FR)
maxCPC : 3.00
OldCPC :0.46
firstPositionCpc : --
topOfPageCpc : 0.46
firstPageCpc : 0.05
NewCPC : --
考虑到您有3个比较,上面的内容没有真正意义,因此我的答案将基于您想要
firstPosition>0
的假设

所以我需要检查一个值类型是否为number,以及该值是否在某个范围内,因此请使用您的第一个if语句:

KeywordIdReport :97483945
campaignName :BP 2015 QC (FR)
maxCPC: 3.00
OldCPC :1.96
firstPositionCpc : 4.28
topOfPageCpc : 1.68
firstPageCpc : 0.85
NewCPC : 4.28

<代码> >(第一位置Copy&)(0位&第一位CPC)我不知道是否是整个问题,但是JavaScript(如C、C++、爪哇、C等)和B语法传统中的其他语言不支持<代码> 0
if (firstPositionCpc && (firstPosition > 0 && firstPositionCpc <= maxCPC)) {
    var newCPC = firstPositionCpc;
}