DEV Community 👩‍💻👨‍💻

Cover image for Absolute Beginner Programming Challenges Part - I: Conditional Statement
Mohammed J Hossain
Mohammed J Hossain

Posted on

Absolute Beginner Programming Challenges Part - I: Conditional Statement

The Challenge

I have gone through 100s of articles looking for absolute beginner's challenges for a friend who is trying to learn how to program for the first time. The challenge that I faced was most articles went directly in to create applications, (with all due respect) even if they sound beginner-friendly for someone who knows how to program, it doesn't sound the same for someone who is learning. So, I decided to write some small fun code-challenges when learning to program for the first time.

How can we Tackle this?

In order to help my friend and hopefully others, I will be posting a series of articles/posts where I will describe a small fun program to test what you learned and also to understand it better.

Everything will be organized by the topics you need to cover and for all these challenges below, you'll need to know the following:

1. Print statement on the screen.
2. How to declare a variable.
3. Take user input.
4. Primitive Operators. (+, -, /, %, =)
5. Comparison Operators. (>, <, >=, <=, ==, !=)


Practice Conditional Statements

For this challenge, you need to know if.. else statement.

Program that identifies if a number is positive or negative.

Step 1: Take user input.

The first step is to ask the user to enter a number and store it in a variable. (for this example we will call it userInput)

Step 2: Run a modulo operation inside if condition.

In this step, we will run the modulo operator(%) which performs a division on a number and returns the remainder of it.

What we will do is userInput % 2, which will return us the remainder of the userInput divided by 2.

Quick math tip: any even number divided by 2 will have a remainder of 0.

So, our condition will be if the remainder is 0 then the number is even and if it's not 0 (userInput % 2 != 0) then its an odd number.

Step 3: Print result into the screen.

In this step, you can print the result in whatever format you like.

Top comments (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.