Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
144 views
in Technique[技术] by (71.8m points)

javascript - 如何确定JavaScript中数字是否为奇数(How to determine if a number is odd in JavaScript)

谁能指出一些代码来确定JavaScript中的数字是偶数还是奇数?

  ask by Jannie Theunissen translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use the below code:(使用以下代码:)

function isOdd(num) { return num % 2;} console.log("1 is " + isOdd(1)); console.log("2 is " + isOdd(2)); console.log("3 is " + isOdd(3)); console.log("4 is " + isOdd(4)); 1 represents an odd number, while 0 represents an even number.(1代表奇数,0代表偶数。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...