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

              
                <html>
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tailwindcss/dist/tailwind.min.css">
    <style>
      .quiz-container {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        min-height: 100vh;
      }
      .quiz-question {
        font-size: 2rem;
        text-align: center;
        margin-bottom: 1rem;
      }
      .quiz-answer-container {
        display: flex;
        justify-content: space-between;
        width: 60%;
      }
      .quiz-answer {
        font-size: 1.5rem;
        cursor: pointer;
      }
      .quiz-score {
        font-size: 1.5rem;
        margin-top: 1rem;
      }
      .quiz-form {
        display: flex;
        flex-direction: column;
        align-items: center;
      }
      .quiz-form-input {
        width: 100%;
        padding: 0.5rem;
        margin-bottom: 1rem;
        font-size: 1.5rem;
        border: 1px solid #ccc;
        border-radius: 4px;
      }
      .quiz-form-submit {
        background-color: #06129b;
        color: white;
        font-size: 1.5rem;
        padding: 0.5rem 1rem;
        border: none;
        border-radius: 4px;
        cursor: pointer;
      }
      @media (max-width: 768px) {
        .quiz-container {
          width: 90%;
        }
        .quiz-answer-container {
          flex-direction: column;
          align-items: center;
        }
        .quiz-answer {
          width: 80%;
          margin-bottom: 0.5rem;
        }
        .quiz-form-input {
          width: 80%;
        }
      }
    </style>
  </head>
  <body class="bg-gray-100 font-sans">
    <div class="quiz-container">
      <form id="quiz-form" class="quiz-form">
        <input type="text" id="name" class="quiz-form-input" placeholder="Enter your name">
        <input type="email" id="email" class="quiz-form-input" placeholder="Enter your email">
        <button type="submit" class="quiz-form-submit">Start quiz</button>
      </form>
      <div id="quiz-question" class="quiz-question text-2xl font-bold text-gray-700"></div>
      <div id="quiz-answer-container" class="quiz-answer-container">
        <div id="quiz-answer-1" class="quiz-answer bg-white rounded-lg shadow-md p-2 text-gray-700 hover:bg-gray-200">Answer 1</div>
<div id="quiz-answer-2" class="quiz-answer bg-white rounded-lg shadow-md p-2 text-gray-700 hover:bg-gray-200">Answer 2</div>
</div>
<div id="quiz-score" class="quiz-score text-xl font-bold text-gray-700"></div>
<div id="quiz-results" class="quiz-results text-xl font-bold text-gray-700" style="display:none;">
<p>Quiz complete!</p>
<p>Your score: <span id="score"></span>/<span id="total-questions"></span></p>
<p>Your name: <span id="name-display"></span></p>
<p>Your email: <span id="email-display"></span></p>
</div>
</div>
<script>
      const quizQuestions = [
        {
          question: "What is the capital of France?",
          answers: ["Paris", "Rome"],
          correctAnswer: "Paris"
        },
        {
          question: "What is the tallest mountain in the world?",
          answers: ["Mount Everest", "K2"],
          correctAnswer: "Mount Everest"
        },
        {
          question: "What is the currency of Japan?",
          answers: ["Yen", "GBP"],
          correctAnswer: "New York City"
        },
        {
          question: "Who painted the Mona Lisa?",
          answers: ["Vincent van Gogh", "Leonardo da Vinci"],
          correctAnswer: "Leonardo da Vinci"
        },
        {
          question: "How many Great Lakes are there in the United States?",
          answers: ["7", "5"],
          correctAnswer: "5"
        },
        {
          question: "Who is the CEO of anythingprogramming",
          answers: ["Dennis", "Elliot"],
          correctAnswer: "Elliot"
        },
        {
          question: "What is the largest planet in the solar system?",
          answers: ["Saturn", "Jupiter"],
          correctAnswer: "Jupiter"
        },
        {
          question: "What is the capital of Australia?",
          answers: ["Melbourne", "Canberra"],
          correctAnswer: "Canberra"
        },
        {
          question: "What is the capital of Canada?",
          answers: ["Montreal", "Toronto"],
          correctAnswer: "Toronto"
        },
        {
          question: "Who wrote the novel 'Pride and Prejudice'?",
          answers: ["Charlotte Bronte", "Jane Austen"],
          correctAnswer: "Jane Austen"
        },
        {
          question: "What is the capital of India?",
          answers: ["Mumbai", "New Delhi"],
          correctAnswer: "New Delhi"
        },
        // Add more questions here
      ];let currentQuestion = 0;
let score = 0;

  const quizFormEl = document.getElementById("quiz-form");
  const quizQuestionEl = document.getElementById("quiz-question");
  const quizAnswer1El = document.getElementById("quiz-answer-1");
  const quizAnswer2El = document.getElementById("quiz-answer-2");
  const quizScoreEl = document.getElementById("quiz-score");
  const quizResultsEl = document.getElementById("quiz-results");
  const nameDisplayEl = document.getElementById("name-display");
  const emailDisplayEl = document.getElementById("email-display");
  const scoreEl = document.getElementById("score");
  const totalQuestionsEl = document.getElementById("total-questions");
  
  function displayQuestion() {
    const question = quizQuestions[currentQuestion];
    quizQuestionEl.textContent = question.question;
    quizAnswer1El.textContent = question.answers[0];
    quizAnswer2El.textContent = question.answers[1];
  }
  
  function checkAnswer(event) {
    const clickedAnswer = event.target.textContent;
    const correctAnswer = quizQuestions[currentQuestion].correctAnswer;
    if (clickedAnswer === correctAnswer) {
      score++;
    }
    currentQuestion++;
    if (currentQuestion < quizQuestions.length) {
      displayQuestion();
    } else {
      quizFormEl.style.display = "none";
      quizQuestionEl.style.display = "none";

quizAnswer1El.style.display = "none";
quizAnswer2El.style.display = "none";
quizResultsEl.style.display = "block";
scoreEl.textContent = score;
totalQuestionsEl.textContent = quizQuestions.length;
nameDisplayEl.textContent = document.getElementById("name").value;
emailDisplayEl.textContent = document.getElementById("email").value;
}
}

  quizFormEl.addEventListener("submit", (event) => {
    event.preventDefault();
    quizFormEl.style.display = "none";
    quizQuestionEl.style.display = "block";
    quizAnswer1El.style.display = "block";
    quizAnswer2El.style.display = "block";
    displayQuestion();
  });
  quizAnswer1El.addEventListener("click", checkAnswer);
  quizAnswer2El.addEventListener("click", checkAnswer);
</script>
  </body>
</html>



              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console