Programming with JavaScript

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

Number is positive or negative

Example 14:

Write a JavaScript to check whether a number is positive or negative

Code

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

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

if (n > 0) {
  console.log(`${n} is positive`);
} else if (n < 0) {
  console.log(`${n} is negative`);
} else {
  console.log(`${n} is zero`);
}

Output

Loading

Views: 72

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments