Skip to main content

Command Palette

Search for a command to run...

Building a Voter's Eligibility Checker

Updated
β€’2 min read
Building a Voter's Eligibility Checker
B
I'm a CS Student exploring the WORLD of Tech with Deep Interest In CyberSecurity & Data Currently, I'm documenting my journey as I master JavaScript and build functional projects from scratch. My goal is to bridge the gap btw technical logic and real world security solutions. Love alot of researching and I've also learned how to help other beginners grow. Tag Along, as I turn Hello World into something much bigger!.

Few days ago, I officially started my journey into software development. As a Computer Science student, I know that theory is important, but building actual projects is where the real learning happens. My very first task? Creating a Voting Eligibility Checker.

The Goal

I wanted to write a script that takes a person's age and determines if they are old enough to vote. In Nigeria, the voting age is 18, so the logic was simple but fundamental.

The Code

Here is the script I wrote and pushed to my GitHub πŸ‘‡πŸ½πŸ‘‡πŸ½πŸ‘‡πŸ½

' ' ' javascript

// Start of code

let ageInput = prompt("Please enter your age to check your voting eligibility:");

let userAge = Number(ageInput);

if (isNaN(userAge)) {

console.log("Error: Please enter a valid number for your age. ");

} else if (userAge >= 18) {

console.log("You are " + userAge + " years old. You're eligible to vote! βœ…");

} else {

console.log("You are " + userAge + " years old. You aren't eligible to vote yet. ❌");

}

// End of code

' ' '

What Learned:

Variables: How to store data (the age).

Conditional Logic: Using if/else statements to make the computer "decide" based on a condition.

The Console: How to output results to see if my logic worked.

Final Thoughts

It’s a small start, but it felt great to see the computer respond to my logic. This project taught me that even a few lines of code can solve a real world 🌍 question. Next, I'll be moving on to more complex tasks like loops and arrays.

Challenge:

I want to make this script more better and advanced. Can you modify this code to tell the user exactly how many years they need to wait if they aren't 18 yet? Drop you Solution in the comments below. Let's learn from each other! Thanks πŸ™πŸ½!!