Logo LIBR
Halo

Portfolio

Back to Blog
8 min read
Challenge Day 6June 15, 2025

Odd, Even, or Special?

JavaScript, Conditions, Logic
Syifa Fauziyah Arizal

Today's challenge focuses on number classification with layered logic to sharpen coding reasoning skills, including checking for odd, even, and multiples of 10.

The goal of this challenge was to classify numbers as odd, even, or special cases such as multiples of 10 while practicing conditional logic.

Example Output
Enter a number: 27
➡️ 27 is an odd number 🔹

Enter a number: 44
➡️ 44 is an even number 🔸

Enter a number: 30
🎉 30 is an even number & multiple of 10!

Challenge Goals

This challenge focuses on nested conditions, number classification, input validation, and creating more user-friendly outputs.

Basic Implementation

Initial Version
const input = parseInt(prompt("Enter a number:"));

if (isNaN(input)) {
    console.log("Please enter a valid number 😅");
} else if (input % 2 === 0) {
    console.log("This is an even number 👍");
} else {
    console.log("This is an odd number 👌");
}

This version can already distinguish between odd and even numbers, but there is still room for improvement.

Adding a Special Case

Multiples of 10 should be checked before the general even-number condition because every multiple of 10 is already an even number.

Enhanced Condition
else if (input % 10 === 0 && input % 2 === 0)

Version With Special Logic

With Special Case
const input = parseInt(prompt("Enter a number:"));

if (isNaN(input)) {
    console.log("Please enter a valid number 😅");
} else if (input % 10 === 0 && input % 2 === 0) {
    console.log("🎉 This is an even number and multiple of 10!");
} else if (input % 2 === 0) {
    console.log("🔸 This is an even number!");
} else {
    console.log("🔹 This is an odd number!");
}

Bonus Challenge: Loop Version

To make the program more interactive, I added a loop that keeps asking for input until the user decides to quit.

Interactive Version
let input;

while (true) {
    input = prompt("Enter a number (type 'exit' to quit)");

    if (input === "exit") {
        console.log("Goodbye! 👋");
        break;
    }

    const number = parseFloat(input);

    if (isNaN(number)) {
        console.log("❌ Please enter a valid number 😅");
    } else if (number % 10 === 0 && number % 2 === 0) {
        console.log("🎊 This is an even number and multiple of 10!");
    } else if (number % 2 === 0) {
        console.log("🔸 This is an even number!");
    } else {
        console.log("🔹 This is an odd number!");
    }
}

Final Version

Complete Solution
let input;

while (true) {
    input = prompt("Enter a number (type 'exit' to quit)");

    if (input === "exit") {
        console.log("Goodbye! 👋");
        break;
    }

    const number = parseFloat(input);

    if (isNaN(number)) {
        console.log("❌ Please enter a valid number 😅");
    } else if (number < 0) {
        console.log("📉 This is a negative number...");
    } else if (number % 10 === 0 && number % 2 === 0) {
        console.log("🎊 This is an even number and multiple of 10!");
    } else if (number % 2 === 0) {
        console.log("🔸 This is an even number!");
    } else {
        console.log("🔹 This is an odd number!");
    }
}
Number: 30
Output: Even number & multiple of 10 🎉

Key Takeaways

This challenge taught me how to organize conditional logic, validate user input, handle special cases, and create a more interactive experience using loops and friendly feedback.

More to read