我有这个javascript函数来验证一个数字是否大于另一个数字,但我想知道我想知道的是多少。那么24是> 10但我想知道多少14。
if(ranNum > numbered){
alert("ranNum is greater than your number");
}else if(ranNum < numbered){
alert("ranNum is less then your number");
}else if(ranNum === numbered){
alert("match");
}else{
alert("try again");
}
答案 0 :(得分:0)
通过减去两个数字并将其添加到警报来创建diff变量。
Var diff = Math.abs (ranNum - numbered);
if(ranNum > numbered) {
alert("ranNum is greater than your number by: " + diff);
}
else if(ranNum < numbered) {
alert("ranNum is less then your number by: " + diff);
}
else if(ranNum === numbered) {
alert("match");
}
else{
alert("try again");
}