<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Name Calculator</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <h1>Name Calculator</h1>
        <input type="text" id="name" placeholder="Enter your full name">
        <button id="calculate">Calculate</button>
        <h2 id="result"></h2>
        <h2 id="personality-number"></h2>
        <h2 id="lucky-color"></h2>
        <h2 id="lucky-month"></h2>
        <h2 id="lucky-year"></h2>
        <h2 id="lucky-day"></h2>
        <hr>
        <p>Created by: Babar Ali</p>
        <p>Date: 9/4/2024, Wednesday, 12:01 PM</p>
        <p>Visit my blog: <a href="https://codecrafti.blogspot.com" target="_blank">CodeCrafti</a></p>
        <p>Follow me on Facebook: <a href="https://www.facebook.com/emotionalfeeling5022" target="_blank">Emotional Feeling</a></p>
    </div>

    <script src="script.js"></script>
</body>
</html>
body {
    font-family: Arial, sans-serif;
    text-align: center;
    background-color: red; /* Add red background color */
}

.container {
    background-color: white; /* Add white background color for the container */
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

#result, #personality-number, #lucky-color, #lucky-month, #lucky-year, #lucky-day {
    margin-top: 20px;
}
const nameInput = document.getElementById('name');
const calculateButton = document.getElementById('calculate');
const resultElement = document.getElementById('result');
const personalityNumberElement = document.getElementById('personality-number');
const luckyColorElement = document.getElementById('lucky-color');
const luckyMonthElement = document.getElementById('lucky-month');
const luckyYearElement = document.getElementById('lucky-year');

calculateButton.addEventListener('click', () => {
    const name = nameInput.value;
    const nameLength = name.length;
    const result = `Your name has ${nameLength} letters.`;

    // Calculate Personality Number
    const personalityNumber = calculatePersonalityNumber(name);
    const personalityResult = `Your Personality Number is ${personalityNumber}.`;

    // Calculate Lucky Color
    const luckyColor = calculateLuckyColor(personalityNumber);
    const luckyColorResult = `Your Lucky Color is ${luckyColor}.`;

    // Calculate Lucky Month
    const luckyMonth = calculateLuckyMonth(personalityNumber);
    const luckyMonthResult = `Your Lucky Month is ${luckyMonth}.`;

    // Calculate Lucky Year
    const luckyYear = calculateLuckyYear(personalityNumber);
    const luckyYearResult = `Your Lucky Year is ${luckyYear}.`;

    resultElement.innerText = result;
    personalityNumberElement.innerText = personalityResult;
    luckyColorElement.innerText = luckyColorResult;
    luckyMonthElement.innerText = luckyMonthResult;
    luckyYearElement.innerText = luckyYearResult;
});

function calculatePersonalityNumber(name) {
    const nameArray = name.split('');
    const consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'];
    let personalityNumber = 0;

    for (let i = 0; i < nameArray.length; i++) {
        const letter = nameArray[i].toLowerCase();
        if (consonants.includes(letter)) {
            personalityNumber += getLetterValue(letter);
        }
    }

    return personalityNumber % 9 || 9; // Ensure the result is between 1 and 9
}

function calculateLuckyColor(personalityNumber) {
    switch (personalityNumber) {
        case 1:
            return 'Red';
        case 2:
            return 'Orange';
        case 3:
            return 'Yellow';
        case 4:
            return 'Green';
        case 5:
            return 'Blue';
        case 6:
            return 'Indigo';
        case 7:
            return 'Violet';
        case 8:
            return 'Pink';
        case 9:
            return 'Brown';
        default:
            return 'Gray';
    }
}

function calculateLuckyMonth(personalityNumber) {
    switch (personalityNumber) {
        case 1:
            return 'January';
        case 2:
            return 'February';
        case 3:
            return 'March';
        case 4:
            return 'April';
        case 5:
            return 'May';
        case 6:
            return 'June';
        case 7:
            return 'July';
        case 8:
            return 'August';
        case 9:
            return 'September';
        default:
            return 'October';
    }
}

function calculateLuckyYear(personalityNumber) {
    const currentYear = new Date().getFullYear();
    return currentYear + personalityNumber;
}

function getLetterValue(letter) {
    switch (letter) {
        case 'b':
        case 'p':
        case 'r':
            return 1;
        case 'c':
        case 'g':
        case 'j':
        case 'k':
        case 'q':
        case 's':
        case 'x':
        case 'z':
            return 2;
        case 'd':
        case 't':
            return 3;
        case 'f':
        case 'v':
            return 4;
        case 'h':
            return 5;
        case 'l':
            return 6;
        case 'm':
            return 7;
        case 'n':
            return 8;
        case 'w':
            return 9;
        default:
            return 0;
    }
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.