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

              
                  <main role="main" class="container">
    <div class="d-flex align-items-center p-3 my-3 text-white-50 bg-purple rounded shadow-sm">
      <img class="mr-3" src="https://cdn-icons.flaticon.com/png/512/3407/premium/3407038.png?token=exp=1657450157~hmac=56962ab70c267a068444924fe3c9eca3" alt="" width="48" height="48">
      <div class="lh-100">
        <h3 class="mb-0 text-white lh-100">Quiz Demo</h3>
        <small>Test your knowledge</small>
      </div>
    </div>

    <div class="my-3 p-3 bg-white rounded shadow-sm position-relative">

      <h4 class="alert alert-success count-down-box position-absolute ">
        <small class="mr-1">Quiz Time</small> <span class="badge badge-dark" id="count-down">1:30</span>
      </h4>

      <button type="button"
        class="d-flex align-items-center justify-content-center btn btn-success btn-lg btn-block start-to-quiz">
     
        <div class="quiz-start-text">Start To Quiz</div>
      </button>
      <h3 style="display: none;" class="pb-2 mb-3 question-title">Questions</h3>
      <div class="mt-4 accordion quiz-item-container" id="accordionExample">
      </div>
    </div>

    <div style="display: none;" class="my-3 p-3 bg-white rounded shadow-sm result-container">

      <button id="show-result" type="button" class="btn btn-outline-danger" data-toggle="modal"
        data-target="#resultModal">
        Show Results
      </button>

      <div class="modal fade" id="resultModal" tabindex="-1">
        <div class="modal-dialog modal-dialog-centered" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <h5 class="modal-title">Results</h5>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body selected-answer-result">


            </div>
            <div class="modal-footer justify-space-between">
              <div class="total-point"><strong>YOUR POINT:</strong> <strong
                  class="alert alert-success user-point">?</strong> / 100</div>
            </div>
          </div>
        </div>
      </div>
    </div>

  </main>


  <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

              
            
!

CSS

              
                body {
    background-color: #f8f9fa!important;
}
*:focus {outline: none !important; box-shadow: none  !important;}
.bg-purple {
    background-color: #6f42c1;
}
.answer-choices-box input{
    display: none;
}
input[type="radio"] + label{ 
    cursor: pointer;
}
input[type="radio"]:checked+label{ 
    background: #ff9800;
    color: #fff;
}
.count-down-box{
    right: 1rem;
    top:1rem;
    padding: 10px;
}
.count-down-box .badge{
    min-width: 80px;
    line-height: 30px;
}
.quiz-start-icon{
    width:100px;height:100px; display:block;
}
.quiz-start-text{
    font-size:60px; font-weight:bolder; margin-left:20px;
}
.start-to-quiz{
    margin-top:70px;
    padding:40px;
}
.d-flex.d-none{
    display: none !important;
}


@keyframes flipInX {
    from {
      -webkit-transform: perspective(400px) rotate3d(1, 0, 0, 90deg);
      transform: perspective(400px) rotate3d(1, 0, 0, 90deg);
      -webkit-animation-timing-function: ease-in;
      animation-timing-function: ease-in;
      opacity: 0;
    }
  
    40% {
      -webkit-transform: perspective(400px) rotate3d(1, 0, 0, -20deg);
      transform: perspective(400px) rotate3d(1, 0, 0, -20deg);
      -webkit-animation-timing-function: ease-in;
      animation-timing-function: ease-in;
    }
  
    60% {
      -webkit-transform: perspective(400px) rotate3d(1, 0, 0, 10deg);
      transform: perspective(400px) rotate3d(1, 0, 0, 10deg);
      opacity: 1;
    }
  
    80% {
      -webkit-transform: perspective(400px) rotate3d(1, 0, 0, -5deg);
      transform: perspective(400px) rotate3d(1, 0, 0, -5deg);
    }
  
    to {
      -webkit-transform: perspective(400px);
      transform: perspective(400px);
    }
  }
  
  .flipInX {
    -webkit-backface-visibility: visible !important;
    backface-visibility: visible !important;
    -webkit-animation-name: flipInX;
    animation-name: flipInX;
    -webkit-animation-duration: 1s;
    animation-duration: 1s;
    -webkit-animation-fill-mode: both;
    animation-fill-mode: both;
  }
  
  
              
            
!

JS

              
                "use stict";
let choisesAnsData,
  quizItemTemplate = "",
  quizItemContainer = document.querySelector('.quiz-item-container'),
  quizChoicesContainer = document.querySelector('.answer-choices-box'),
  selectedAnswerResult = document.querySelector('.selected-answer-result'),
  questionTitle = document.querySelector('.question-title'),
  startQuiz = document.querySelector('.start-to-quiz'),
  userPointBox = document.querySelector('.user-point'),
  resultModal = document.querySelector('#resultModal'),
  showResult = document.querySelector('#show-result'),
  showResultContainer = document.querySelector('.result-container'),
  timerBox = document.querySelector("#count-down");

let allQuestionsData = [
  {
    questionID: 1,
    question: "Türkiye\'nin Başkenti Neresidir?",
    answers: [
      { opC: "a", opT: "Ordu" },
      { opC: "b", opT: "Ankara" },
      { opC: "c", opT: "İstanbul" },
      { opC: "d", opT: "Mersin" }
    ]
  },
  {
    questionID: 2,
    question: "Ani Harabeleri Hangi İlimizdedir?",
    answers: [
      { opC: "a", opT: "Zonguldak" },
      { opC: "b", opT: "Manisa" },
      { opC: "c", opT: "Nevşehir" },
      { opC: "d", opT: "Kars" }
    ]
  },
  {
    questionID: 3,
    question: "Peri Bacaları Hangi İlimizdedir?",
    answers: [
      { opC: "a", opT: "Erzurum" },
      { opC: "b", opT: "Edirne" },
      { opC: "c", opT: "Kırklareli" },
      { opC: "d", opT: "Nevşehir" }
    ]
  },
  {
    questionID: 4,
    question: "Topkapı Sarayı Nerededir?",
    answers: [
      { opC: "a", opT: "İstanbul" },
      { opC: "b", opT: "Antalya" },
      { opC: "c", opT: "Burdur" },
      { opC: "d", opT: "Bursa" }
    ]
  },
  {
    questionID: 5,
    question: "Türkiye Cumhuriyeti'nin Kurucusus Kimdir?",
    answers: [
      { opC: "a", opT: "Kazim Karabekir" },
      { opC: "b", opT: "İsmet İnönü" },
      { opC: "c", opT: "Mustafa Kemal Atatürk" },
      { opC: "d", opT: "Mehmet Akif Ersoy" }
    ]
  }
];

let correctAnswers = [
  {
    questionID: 1,
    correctAnswer: "b"
  },
  {
    questionID: 2,
    correctAnswer: "d"
  },
  {
    questionID: 3,
    correctAnswer: "d"
  },
  {
    questionID: 4,
    correctAnswer: "d"
  },
  {
    questionID: 5,
    correctAnswer: "c"
  }
];

let selectedData = [];

let unitePoint = 100 / allQuestionsData.length;

function renderToData() {
  allQuestionsData.map(questions => {
    quizItemTemplate += `<div class="card answer-item-box ">
    <button style="animation-delay:${questions.questionID / 10}s" class="question-item-btn btn btn-dark btn-lg btn-block mb-1 rounded-0 text-left flipInX" type="button" data-toggle="collapse" data-target="#q-${questions.questionID}">
      <span class="badge badge-light mr-2">${questions.questionID} </span> ${questions.question}
    </button>
    <div id="q-${questions.questionID}" class="collapse" data-parent="#accordionExample">
      <div class="card-body answer-choices-box">
          ${
      questions.answers.map(items =>
        `
        <div class="d-flex align-items-center mb-3">
          <input type="radio" id="op-${questions.questionID}-${items.opC}" name="customRadio" class="mr-3" 
          onchange="setAnswer('${questions.questionID}', '${items.opC}', '${items.opT}')">
          <label class="mb-0 w-100 alert alert-secondary" for="op-${questions.questionID}-${items.opC}">
          <span class="badge badge-light mr-2">${items.opC} </span>
          ${items.opT}</label>
        </div>
        `
      ).join("")
      }
      </div>
    </div>
    </div>`;
  });
  quizItemContainer.innerHTML = quizItemTemplate;
}

startQuiz.addEventListener("click", function () {
  this.classList.toggle("d-none");
  questionTitle.style.display = "block";
  renderToData();
  timer(1, 30);
});

function setAnswer(id, sign, name) {
  let newObj = { answerID: parseInt(id), answerSign: sign, answerName: name, correctSign: false };
  if (selectedData.filter(item => item.answerID === parseInt(id)).length === 0) {
    selectedData.push(newObj);
  }
  else {
    let answerValues = selectedData.filter(item => item.answerID === newObj.answerID)[0];
    answerValues.answerSign = sign;
    answerValues.answerName = name;
    answerValues.correctSign = false;
  }

  correctAnswers.filter(item => item.questionID === parseInt(id))
    .filter(fin => {
      if (fin.correctAnswer === sign) {
        selectedData.filter(item => item.answerID === newObj.answerID)[0].correctSign = true;
      }
    });

  // All questions are solved controler
  selectedData.length === allQuestionsData.length ? showResultContainer.style.display = "block" : "none";

}

// Show ressult fire
showResult.addEventListener("click", function () {
  let selectedAnswersTemplate = "";
  selectedData.sort(function (a, b) {
    return a.answerID - b.answerID;
  });

  selectedData.map(item => {
    selectedAnswersTemplate += `
        <div class="alert alert-${item.correctSign === true ? "success" : "danger"}">
          <span class="badge badge-light mr-2">${item.answerID}. Question - ${item.answerSign.toUpperCase()} </span> 
          ${item.correctSign === true ? "<span class='badge badge-success'>True</span>" : "<span class='badge badge-danger'>False</span>"}
          ${item.answerName}
        </div>
    `;
  });
  
  selectedAnswerResult.innerHTML = selectedAnswersTemplate;

  let totapPoint = selectedData.filter(trueVal => trueVal.correctSign === true).reduce((calc) => {
    return calc + unitePoint;
  }, 0);

  userPointBox.innerHTML = totapPoint;

  setQuestionsDisabled();
  clearInterval(timerFire);
  hideAllCollapse();
});



// Timer
let timerFire;
function timer(minute, second) {
  timerFire = setInterval(contDown, 1000);
  function contDown() {
    second--;
    let currentTime = minute + ":" + (second < 10 ? "0" : "") + second;
    timerBox.innerHTML = currentTime;
    if (second === 0) {
      if (minute > 0 && second === 0) {
        minute--;
        second = 60;
      } else {
        clearInterval(timerFire);
        setQuestionsDisabled();
        showResult.click();
        hideAllCollapse();
      }
    }
  }
}

// If the time is over all question items are disabled
function setQuestionsDisabled() {
  let questionItemBtn = document.querySelectorAll('.question-item-btn');
  questionItemBtn.forEach(function (item) {
    item.setAttribute("disabled", "true");
  });
}

// When finish quiz, hide all collapse
function hideAllCollapse() {
  let allCollapse = document.querySelectorAll('.collapse');
  allCollapse.forEach(function (item) {
    item.classList.remove("show");
  });
}















              
            
!
999px

Console