function Method(Distance,Cost,Milage) {
result1=parseInt(Distance/Cost*Milage);
result2=parseInt(Distance/46*Cost);
alert('Your trip will costs '+ result1 +' $');
alert('Your trip in hybrid costs '+ result2 +' $');
if ((result1-result2)<0)
alert('You will save '+(result2-result1)+' $');
else
alert('You will save '+(result1-result2)+' $');
}
}
我能做些什么来缩短这个时间?
最佳答案
是的:
alert("You will save "+Math.abs(result1-result2)+" $");
这将始终将“间隙”输出为正数。
顺便说一句,parseInt
是多余的,因为您已经使用 /
和 *
运算符将其转换为数字。
关于javascript - 如何使这个成本计算器脚本更短?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23000790/