在Javascript中测试偶数/奇数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Javascript中测试偶数/奇数相关的知识,希望对你有一定的参考价值。
One of those common tools that's easy to forget about is the Modulus operator (%), which returns the remainder of a division operation.If you divide some number by two, a remainder of 0 indicates an even number, while a remainder of 1 indicates an odd number.
var isEven = function(someNumber){ return (someNumber%2 == 0) ? true : false; }; alert(isEven(64)); // Alerts "true". alert(isEven(97)); // Alerts "false".
以上是关于在Javascript中测试偶数/奇数的主要内容,如果未能解决你的问题,请参考以下文章
如何在Javascript中为1到1000的奇数和偶数编写脚本?