QUIZ: Positive or Negative Number?

QUIZ: Positive or Negative Number?

Let’s test your logic! Can you determine if a number is positive or negative?
This is a fundamental concept in programming. Ready for a quick challenge?

The Challenge

Write a simple logic check (in any language you prefer!) to determine if a
given number is greater than 0.

Hint

Think about the basic comparison operators. Which one helps you check if a
value is larger than another?

The Code (JavaScript Example)

      
        function isPositive(number) {
          if (number > 0) {
            return true;
          } else {
            return false;
          }
        }

        // Let's test it!
        console.log(isPositive(5));   // Output: true
        console.log(isPositive(-2));  // Output: false
        console.log(isPositive(0));   // Output: false
      
    

Brain Check!

Okay, hotshot! What will be the output of isPositive(-5)?

Click for answer!

The output will be false. -5 is not greater than 0.

Your Turn

Now that you’ve seen the solution, how would you write this in a
different programming language? Share your code in the comments below!

Share this Post

Leave a Reply

Your email address will not be published. Required fields are marked *