HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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">×</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>
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;
}
"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");
});
}
Also see: Tab Triggers