Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Random Quiz</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div id="quiz-container">
        <h1>Quick Quiz</h1>
        <div class="question">
            <h2>Question 1: What is the capital of France?</h2>
            <ul>
                <li><input type="radio" name="q1" value="Paris"> Paris</li>
                <li><input type="radio" name="q1" value="London"> London</li>
                <li><input type="radio" name="q1" value="Berlin"> Berlin</li>
            </ul>
        </div>
        <div class="question">
            <h2>Question 2: What is 2 + 2?</h2>
            <ul>
                <li><input type="radio" name="q2" value="3"> 3</li>
                <li><input type="radio" name="q2" value="4"> 4</li>
                <li><input type="radio" name="q2" value="5"> 5</li>
            </ul>
        </div>
        <div class="question">
            <h2>Question 3: What is the largest planet in our solar system?</h2>
            <ul>
                <li><input type="radio" name="q3" value="Earth"> Earth</li>
                <li><input type="radio" name="q3" value="Mars"> Mars</li>
                <li><input type="radio" name="q3" value="Jupiter"> Jupiter</li>
            </ul>
        </div>
        <button id="submit-button">Submit</button>
        <div id="result"></div>
    </div>
    <script src="script.js"></script>
</body>
</html>

              
            
!

CSS

              
                /* Styling for the quiz container */
#quiz-container {
    width: 80%;
    margin: 0 auto;
    padding: 20px;
    background-color: #f4f4f4;
    border: 1px solid #ccc;
    border-radius: 5px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}

h1 {
    text-align: center;
    font-size: 24px;
    margin-bottom: 20px;
    color: #333;
}

/* Styling for individual questions */
.question {
    background-color: #fff;
    padding: 15px;
    margin-bottom: 20px;
    border: 1px solid #ddd;
    border-radius: 5px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}

h2 {
    font-size: 18px;
    color: #333;
    margin-bottom: 10px;
    border-bottom: 2px solid #007bff; /* Add a blue underline for question titles */
    padding-bottom: 5px;
}

ul {
    list-style-type: none;
    padding: 0;
}

li {
    margin: 5px 0;
    transition: background-color 0.3s ease; /* Add a smooth transition for the background color */
}

/* Hover effect for answer options */
li:hover {
    background-color: #f0f0f0;
}

/* Styling for radio buttons and labels */
input[type="radio"] {
    margin-right: 5px;
}

/* Styling for selected radio buttons and labels */
input[type="radio"]:checked + label {
    font-weight: bold;
    color: #007bff;
}

/* Styling for the Submit button */
#submit-button {
    display: block;
    margin: 20px auto;
    padding: 10px 20px;
    background-color: #007bff;
    color: #fff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

#submit-button:hover {
    background-color: #0056b3;
}

/* Styling for the result display */
#result {
    text-align: center;
    font-size: 20px;
    margin-top: 20px;
    padding: 10px;
    background-color: #4CAF50;
    color: #fff;
    border-radius: 5px;
    display: none;
}

              
            
!

JS

              
                $(document).ready(function() {
    // Function to disable other options when an answer is clicked
    $("input[type='radio']").click(function() {
        var name = $(this).attr("name");
        $("input[name='" + name + "']").attr("disabled", true);
    });

    $("#submit-button").click(function() {
        // Initialize score and incorrect answers
        var score = 0;
        var incorrectAnswers = [];

        // Check answers for each question
        if ($("input[name='q1']:checked").val() === "Paris") {
            score++;
        } else {
            incorrectAnswers.push("q1");
        }
        if ($("input[name='q2']:checked").val() === "4") {
            score++;
        } else {
            incorrectAnswers.push("q2");
        }
        if ($("input[name='q3']:checked").val() === "Jupiter") {
            score++;
        } else {
            incorrectAnswers.push("q3");
        }

        // Display the result
        $("#result").html("You scored " + score + " out of 3 questions.");
        $("#result").show(); // Show the result

        // Change background color of incorrect answer options to red
        for (var i = 0; i < incorrectAnswers.length; i++) {
            $("input[name='" + incorrectAnswers[i] + "'] + label").css("background-color", "#ff4d4d");
        }
    });
});

              
            
!
999px

Console