Programming with JavaScript

⌘K
  1. Home
  2. Docs
  3. Programming with JavaScri...
  4. Example Programs
  5. Number is even or not

Number is even or not

Example 13:

Write a JavaScript to check whether a number is even or not

const prompt = require("prompt-sync")();

let n = prompt("Enter a number");
n = parseInt(n);

if (n % 2 == 0) {
  console.log(`${n} is even`);
} else {
  console.log(`${n} is odd`);
}

Output

Loading

Views: 82

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments