Home>Article>Web Front-end> How to determine odd and even numbers in javascript

How to determine odd and even numbers in javascript

WBOY
WBOY Original
2021-12-07 14:35:17 17049browse

In JavaScript, you can use the if statement, "%" and "==" operators to determine whether the value is divisible by 2, and then determine whether the value is an odd or even number. The syntax is "if(value%2= =0){Even number execution code;}else{Odd number execution code;}".

How to determine odd and even numbers in javascript

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

How to find odd and even numbers in JavaScript

In JavaScript, you can use if statements, % and == operators to find odd and even numbers, example As follows:

      Document 

Output result:

How to determine odd and even numbers in javascript

How to determine odd and even numbers in javascript

##[Recommended learning:

javascript advanced tutorial]

The above is the detailed content of How to determine odd and even numbers in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn