Challenge Day 6

Odd, Even, or Special?

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

Challenge Goals

  • Practice nested conditions (if, else if, else)
  • Understand odd, even, and multiple concepts
  • Add input validation & more human-friendly output

Program Description

  1. User inputs a number
  2. Program checks if the number is:
    • ✅ Odd
    • ✅ Even
    • 🎉 Multiple of 10 (shows special message)
  3. Output includes emojis to make it more expressive 😄
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!
          

Tools & Concepts

  • prompt() and parseInt() to get user input
  • isNaN() for input validation
  • if and else if for conditional logic
  • % (modulus) operator to check odd/even/multiples

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 👌");
}
          

Adding: Multiple of 10

Enhanced Condition

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

Full Code Version 1:

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

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!");
    }
}
          

Addition: Check Negative Numbers

Final Code:

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!");
    }
}
          

Reflection

This challenge taught me many small but important things:

  • Organizing if-else logic so they don't conflict
  • Validating user input in a friendly way
  • Giving expressive feedback through emojis (to make it fun!)
  • Looping with while (true) and break when user wants to stop

Definitely more excited to continue to Day 7! 🚀

View Source Code
Your Logo