In JavaScript, we can easily determine whether a number is positive, negative, or zero by using an if statement.
Here’s an example program that demonstrates this:
// Define a variable to hold the number let num = 5; // Check if the number is positive if (num > 0) { console.log("The number is positive."); } // Check if the number is negative if (num < 0) { console.log("The number is negative."); } // Check if the number is zero if (num === 0) { console.log("The number is zero."); }
In this program, we first define a variable num and assign it the value of 5. We then use three separate if statements to check if num is positive, negative, or zero.
The first if statement checks if num is greater than 0. If it is, then we log the message “The number is positive.” to the console.
The second if statement checks if num is less than 0. If it is, then we log the message “The number is negative.” to the console.
The third if statement checks if num is equal to 0. If it is, then we log the message “The number is zero.” to the console.
By using these three if statements, we can easily determine whether a given number is positive, negative, or zero in JavaScript.