Skip to content
TheChatArchiveThe Chat Archive
o1-mini-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

Create a very modern and futuristic website using HTML CSS and JS i only one file. The…

  1. User

    Create a very modern and futuristic website using HTML CSS and JS i only one file. The website will be a quiz app. It will prompt the user two types of questions randomly:

    • Randomly chooses a capital of any one state of India and prompts the user to give the name of the state, or
    • Randomly choses a capital of India and asks the user to give its capital city
  2. Assistant

    Sure! Below is a complete HTML file that creates a modern and futuristic single-page quiz application. This app randomly prompts the user with one of two types of questions:

    1. Given a capital city of an Indian state, identify the state.
    2. Given an Indian state, identify its capital city.

    The design incorporates a sleek dark theme with subtle animations and transitions to enhance the futuristic feel. All the HTML, CSS, and JavaScript are embedded within a single file for simplicity.

    Feel free to copy the entire code into a file (e.g., quiz.html) and open it in your web browser to see it in action!

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>India Capitals Quiz</title>
        <style>
            /* Reset and basic styles */
            * {
                margin: 0;
                padding: 0;
                box-sizing: border-box;
            }
    
            html, body {
                height: 100%;
                font-family: 'Arial', sans-serif;
                background: linear-gradient(135deg, #1f1c2c, #928dab);
                display: flex;
                justify-content: center;
                align-items: center;
                color: #ffffff;
            }
    
            /* Container */
            .container {
                background: rgba(255, 255, 255, 0.1);
                padding: 40px;
                border-radius: 15px;
                box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
                backdrop-filter: blur(8.5px);
                -webkit-backdrop-filter: blur(8.5px);
                border: 1px solid rgba(255, 255, 255, 0.18);
                width: 90%;
                max-width: 500px;
                text-align: center;
            }
    
            h1 {
                margin-bottom: 20px;
                font-size: 2em;
                letter-spacing: 2px;
                color: #00e6e6;
                animation: neonGlow 1.5s infinite alternate;
            }
    
            @keyframes neonGlow {
                from {
                    text-shadow: 0 0 10px #00e6e6, 0 0 20px #00e6e6, 0 0 30px #00e6e6, 0 0 40px #00e6e6;
                }
                to {
                    text-shadow: 0 0 20px #00fffc, 0 0 30px #00fffc, 0 0 40px #00fffc, 0 0 50px #00fffc;
                }
            }
    
            .question {
                margin: 20px 0;
                font-size: 1.2em;
                min-height: 60px;
                display: flex;
                align-items: center;
                justify-content: center;
            }
    
            input[type="text"] {
                padding: 10px;
                border: none;
                border-radius: 25px;
                width: 80%;
                max-width: 300px;
                outline: none;
                font-size: 1em;
                transition: all 0.3s ease;
            }
    
            input[type="text"]:focus {
                box-shadow: 0 0 10px #00e6e6;
            }
    
            button {
                margin-top: 20px;
                padding: 10px 20px;
                border: none;
                border-radius: 25px;
                background: #00e6e6;
                color: #1f1c2c;
                font-size: 1em;
                cursor: pointer;
                transition: background 0.3s ease, transform 0.2s ease;
            }
    
            button:hover {
                background: #00fffc;
                transform: scale(1.05);
            }
    
            .score {
                margin-top: 15px;
                font-size: 1em;
            }
    
            .feedback {
                margin-top: 10px;
                font-size: 1em;
                min-height: 20px;
            }
    
            /* Responsive */
            @media (max-width: 600px) {
                .container {
                    padding: 20px;
                }
    
                h1 {
                    font-size: 1.5em;
                }
    
                input[type="text"], button {
                    width: 100%;
                    max-width: none;
                }
            }
        </style>
    </head>
    <body>
    
        <div class="container">
            <h1>India Capitals Quiz</h1>
            <div class="question" id="question">
                Loading question...
            </div>
            <input type="text" id="answer" placeholder="Type your answer here">
            <button id="submitBtn">Submit</button>
            <div class="feedback" id="feedback"></div>
            <div class="score" id="score">Score: 0</div>
        </div>
    
        <script>
            // List of Indian states and their capitals
            const statesAndCapitals = {
                "Andhra Pradesh": "Amaravati",
                "Arunachal Pradesh": "Itanagar",
                "Assam": "Dispur",
                "Bihar": "Patna",
                "Chhattisgarh": "Raipur",
                "Goa": "Panaji",
                "Gujarat": "Gandhinagar",
                "Haryana": "Chandigarh",
                "Himachal Pradesh": "Shimla",
                "Jharkhand": "Ranchi",
                "Karnataka": "Bengaluru",
                "Kerala": "Thiruvananthapuram",
                "Madhya Pradesh": "Bhopal",
                "Maharashtra": "Mumbai",
                "Manipur": "Imphal",
                "Meghalaya": "Shillong",
                "Mizoram": "Aizawl",
                "Nagaland": "Kohima",
                "Odisha": "Bhubaneswar",
                "Punjab": "Chandigarh",
                "Rajasthan": "Jaipur",
                "Sikkim": "Gangtok",
                "Tamil Nadu": "Chennai",
                "Telangana": "Hyderabad",
                "Tripura": "Agartala",
                "Uttar Pradesh": "Lucknow",
                "Uttarakhand": "Dehradun",
                "West Bengal": "Kolkata"
            };
    
            const states = Object.keys(statesAndCapitals);
            const capitals = Object.values(statesAndCapitals);
    
            const questionEl = document.getElementById('question');
            const answerEl = document.getElementById('answer');
            const submitBtn = document.getElementById('submitBtn');
            const feedbackEl = document.getElementById('feedback');
            const scoreEl = document.getElementById('score');
    
            let currentQuestion = {};
            let score = 0;
    
            // Function to generate a random number
            function getRandomInt(max) {
                return Math.floor(Math.random() * max);
            }
    
            // Function to generate a new question
            function generateQuestion() {
                feedbackEl.textContent = '';
                answerEl.value = '';
                const questionType = getRandomInt(2); // 0 or 1
    
                if (questionType === 0) {
                    // Given a capital, ask for the state
                    const capital = capitals[getRandomInt(capitals.length)];
                    currentQuestion = {
                        type: 'capitalToState',
                        question: `Which state has the capital city <strong>${capital}</strong>?`,
                        answer: getStateByCapital(capital)
                    };
                } else {
                    // Given a state, ask for the capital
                    const state = states[getRandomInt(states.length)];
                    currentQuestion = {
                        type: 'stateToCapital',
                        question: `What is the capital city of <strong>${state}</strong>?`,
                        answer: statesAndCapitals[state]
                    };
                }
    
                questionEl.innerHTML = currentQuestion.question;
            }
    
            // Helper function to get state by capital
            function getStateByCapital(capital) {
                for (let [state, cap] of Object.entries(statesAndCapitals)) {
                    if (cap.toLowerCase() === capital.toLowerCase()) {
                        return state;
                    }
                }
                return '';
            }
    
            // Function to handle answer submission
            function submitAnswer() {
                const userAnswer = answerEl.value.trim().toLowerCase();
                if (userAnswer === '') {
                    feedbackEl.textContent = 'Please enter an answer.';
                    return;
                }
    
                let correctAnswer = currentQuestion.answer.toLowerCase();
                if (userAnswer === correctAnswer) {
                    feedbackEl.style.color = '#00ff00';
                    feedbackEl.textContent = '✅ Correct!';
                    score++;
                } else {
                    feedbackEl.style.color = '#ff0000';
                    feedbackEl.innerHTML = `❌ Incorrect! The correct answer is <strong>${currentQuestion.answer}</strong>.`;
                }
    
                scoreEl.textContent = `Score: ${score}`;
                // Generate next question after a short delay
                setTimeout(generateQuestion, 1500);
            }
    
            // Event listeners
            submitBtn.addEventListener('click', submitAnswer);
            answerEl.addEventListener('keyup', function(event) {
                if (event.key === 'Enter') {
                    submitAnswer();
                }
            });
    
            // Initial call
            generateQuestion();
        </script>
    
    </body>
    </html>
    

    Explanation of the Code

    1. HTML Structure:

      • Container Div: Holds all the elements of the quiz, including the title, question display, input field, submit button, feedback, and score.
      • Elements:
        • h1: Displays the quiz title with a neon glow animation.
        • div.question: Shows the current question.
        • input#answer: Where users type their answers.
        • button#submitBtn: Button to submit the answer.
        • div.feedback: Provides feedback on whether the answer was correct or incorrect.
        • div.score: Displays the user's current score.
    2. CSS Styling:

      • Reset and Basic Styles: Removes default margins and paddings, sets fonts, and defines the background with a linear gradient for a modern look.
      • Container Styling: Uses a semi-transparent background with a blur effect to create a futuristic glass-like appearance. The container is centered and responsive.
      • Animations:
        • @keyframes neonGlow: Creates a glowing animation for the title to enhance the futuristic feel.
      • Responsive Design: Ensures the quiz looks good on various screen sizes, especially mobile devices.
    3. JavaScript Functionality:

      • Data: An object statesAndCapitals contains Indian states as keys and their respective capitals as values.
      • Variables:
        • states and capitals: Arrays derived from the keys and values of statesAndCapitals for easy access.
        • currentQuestion: Stores the current question's details.
        • score: Tracks the user's score.
      • Functions:
        • getRandomInt(max): Generates a random integer between 0 and max - 1.
        • generateQuestion(): Randomly selects a question type and populates the currentQuestion object with the question and the correct answer. It then updates the DOM to display the question.
        • getStateByCapital(capital): Helper function to retrieve the state name given a capital city.
        • submitAnswer(): Handles the user's answer submission. It validates the input, compares it to the correct answer, updates the score accordingly, provides feedback, and schedules the next question.
      • Event Listeners:
        • submitBtn click event triggers submitAnswer().
        • Pressing the "Enter" key within the answerEl input field also triggers submitAnswer().
      • Initialization: Calls generateQuestion() once when the page loads to present the first question.

    How to Use

    1. Opening the Quiz:

      • Save the provided code snippet into a file named quiz.html.
      • Open the file using any modern web browser (e.g., Chrome, Firefox, Edge).
    2. Playing the Quiz:

      • Read the displayed question carefully.
      • Type your answer into the input field.
      • Click the "Submit" button or press "Enter" to submit your answer.
      • Receive immediate feedback indicating whether your answer was correct.
      • Your current score is updated and displayed below the feedback.
      • After a short delay, the next question will appear automatically.
    3. Enjoy the Experience:

      • The sleek design and animations provide an engaging and modern user experience, making learning about Indian states and their capitals both fun and visually appealing.

    Feel free to customize the styling or add more features, such as a timer, high scores, or additional question types, to enhance the quiz further!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.