Table of Contents
show
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

Views: 72