<div class="quiz">
<h2 class="quiz__type">${question.answerType}</h2>
<h3 class="quiz__question">
<span class="quiz__number">${question.answerNum}. </span>
<span class="quiz__ask">${question.answerAsk}</span>
</h3>
<div class="quiz__view">
<div class="true">정답입니다!</div>
<div class="false">틀렸습니다!</div>
<div class="dog">
<div class="dog">
<div class="head">
<div class="ears"></div>
<div class="face"></div>
<div class="eyes">
<div class="teardrop"></div>
</div>
<div class="nose"></div>
<div class="mouth">
<div class="tongue"></div>
</div>
<div class="chin"></div>
</div>
<div class="body">
<div class="tail"></div>
<div class="legs"></div>
</div>
</div>
</div>
</div>
<div class="quiz__answer">
<div class="quiz__selects">
<label for="select1${number}">
<input class="select" type="radio" id="select1${number}" name="select${number}" value="1">
<span class="choice">${question.answerChoice.a}</span>
</label>
<label for="select2${number}">
<input class="select" type="radio" id="select2${number}" name="select${number}" value="2">
<span class="choice">${question.answerChoice.b}</span>
</label>
<label for="select3${number}">
<input class="select" type="radio" id="select3${number}" name="select${number}" value="3">
<span class="choice">${question.answerChoice.c}</span>
</label>
<label for="select4${number}">
<input class="select" type="radio" id="select4${number}" name="select${number}" value="4">
<span class="choice">${question.answerChoice.d}</span>
</label>
</div>
</div>
</div>
<div>
<button class="quiz__confirm">정답 확인하기</button>
<div class="quiz__result"></div>
</div>
.quiz__wrap {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
margin-top: 150px;
}
.quiz {
max-width: 500px;
width: 100%;
background: #fff;
border: 8px ridge #cacaca;
margin: 10px;
}
.quiz__type {
background: #cacaca;
text-align: center;
font-size: 14px;
color: #3b3b3b;
border: 3px ridge #cacaca;
padding: 3px 0;
position: relative;
}
.quiz__type::before {
content: '';
position: absolute;
left: 2px; top: 4px;
width: 5px;
height: 5px;
border: 6px ridge #ffffff;
}
.quiz__type::after {
content: '';
position: absolute;
right: 2px; top: 4px;
width: 5px;
height: 5px;
border: 6px ridge #ffffff;
}
.quiz__question {
border-top: 6px ridge #cacaca;
border-bottom: 6px ridge #cacaca;
padding: 13px 30px;
font-size: 24px;
line-height: 1.4;
}
.quiz__number {
font-family: 'Cafe24Dangdanghae';
color: #64a30b;
}
.quiz__ask {
font-family: 'Cafe24Dangdanghae';
}
.quiz__view {
background: #f5f5f5;
position: relative;
}
.quiz__view.like .true {
opacity: 1;
animation: wobble 0.6s;
}
.quiz__view.dislike .false {
opacity: 1;
animation: wobble 0.6s;
}
@keyframes wobble {
0% {transform: translateZ(0)}
15% {transform: translate3d(-25%, 0, 0) rotate(-5deg)}
30% {transform: translate3d(20%, 0, 0) rotate(3deg)}
45% {transform: translate3d(-15%, 0, 0) rotate(-3deg)}
60% {transform: translate3d(10%, 0, 0) rotate(2deg)}
75% {transform: translate3d(-5%, 0, 0) rotate(-1deg)}
100% {transform: translateZ(0)}
}
.quiz__view .true {
position: absolute;
right: 70%; top: 100px;
width: 120px;
height: 120px;
background: #F5534F;
border-radius: 50%;
z-index: 100;
line-height: 120px;
text-align: center;
color: #fff;
opacity: 0;
}
.quiz__view .false {
position: absolute;
left: 70%; top: 100px;
width: 120px;
height: 120px;
background: #fff;
border-radius: 50%;
z-index: 100;
line-height: 120px;
text-align: center;
color: #F5534F;
opacity: 0;
}
.quiz__answer {
border-top: 6px ridge #cacaca;
background: #f5f5f5;
padding: 10px;
}
.quiz__confirm {
border: 6px ridge #ffffff;
width: 100%;
font-size: 22px;
padding: 13px 20px;
background: #d6d6d6;
font-family: 'Cafe24Dangdanghae';
text-shadow: 1px 1px 1px #fff;
transition: all 0.3s;
cursor: pointer;
}
.quiz__confirm:hover {
background: #b3b3b3;
}
.quiz__result {
border: 6px ridge #ffffff;
width: 100%;
font-size: 22px;
padding: 13px 20px;
background: #fff;
text-align: center;
font-family: 'Cafe24Dangdanghae';
text-shadow: 1px 1px 1px #fff;
/* display: none; */
}
.quiz__input {
border: 6px ridge #ffffff;
width: 100%;
font-size: 22px;
padding: 13px 20px;
background: #fff;
text-align: center;
font-family: 'Cafe24Dangdanghae';
text-shadow: 1px 1px 1px #fff;
margin-bottom: 10px;
}
.source-btn {
font-family: 'Cafe24Dangdanghae';
position: absolute;
right: 47%; bottom: 100px;
font-size: 16px;
padding: 10px 30px;
border-radius: 50px;
transition: all 0.2s;
cursor: pointer;
}
.source-btn:hover {
background: #000;
color: #fff;
}
const quizWrap = document.querySelector(".quiz__wrap");
const quizInfo = [
{
answerType : "javascript",
answerNum : 1,
answerAsk : "객체 기반의 스크립트 프로그래밍 언어는 무엇입니까?",
answerChoice : {
a: "html",
b: "css",
c: "javascript",
d: "react"},
answerResult : "3",
answerEx : "객체 기반의 스크립트 프로그맹 언어는 자바스크립트입니다."
},
{
answerType : "html",
answerNum : 2,
answerAsk : "다른 콘텐츠와 연결되는 하이퍼링크(hyperlink)를 정의하는 태그는 무엇입니까?",
answerChoice : {
a: "a",
b: "img",
c: "p",
d: "html"},
answerResult : "1",
answerEx : "a 태그는 다른 컨텐츠와 연결되는 하이러핑크를 설정합니다."
},
{
answerType : "css",
answerNum : 3,
answerAsk : "CSS에서 바깥쪽 여백을 설정할때 사용하는 속성은 무엇입니까?",
answerChoice : {
a: "padding",
b: "margin",
c: "border",
d: "overflow"},
answerResult : "2",
answerEx : "margin 으로 바깥쪽 여백을 설정할 수 있습니다."
}
];
function updataQuiz(){
const html = [];
quizInfo.forEach((question, number)=>{
html.push(`<div class="quiz">
<h2 class="quiz__type">${question.answerType}</h2>
<h3 class="quiz__question">
<span class="quiz__number">${question.answerNum}. </span>
<span class="quiz__ask">${question.answerAsk}</span>
</h3>
<div class="quiz__view">
<div class="true">정답입니다!</div>
<div class="false">틀렸습니다!</div>
<div class="dog">
<div class="dog">
<div class="head">
<div class="ears"></div>
<div class="face"></div>
<div class="eyes">
<div class="teardrop"></div>
</div>
<div class="nose"></div>
<div class="mouth">
<div class="tongue"></div>
</div>
<div class="chin"></div>
</div>
<div class="body">
<div class="tail"></div>
<div class="legs"></div>
</div>
</div>
</div>
</div>
<div class="quiz__answer">
<div class="quiz__selects">
<label for="select1${number}">
<input class="select" type="radio" id="select1${number}" name="select${number}" value="1">
<span class="choice">${question.answerChoice.a}</span>
</label>
<label for="select2${number}">
<input class="select" type="radio" id="select2${number}" name="select${number}" value="2">
<span class="choice">${question.answerChoice.b}</span>
</label>
<label for="select3${number}">
<input class="select" type="radio" id="select3${number}" name="select${number}" value="3">
<span class="choice">${question.answerChoice.c}</span>
</label>
<label for="select4${number}">
<input class="select" type="radio" id="select4${number}" name="select${number}" value="4">
<span class="choice">${question.answerChoice.d}</span>
</label>
</div>
</div>
</div>`);
});
html.push(`
<div>
<button class="quiz__confirm">정답 확인하기</button>
<div class="quiz__result"></div>
</div>
`);
quizWrap.innerHTML = html.join('');
}
updataQuiz();
function answerQuiz(){
const quizSelects = document.querySelectorAll(".quiz__selects");
const quizView = document.querySelectorAll(".quiz__view");
const quizResult = document.querySelector(".quiz__result");
let scoreCurrent = 0;
quizInfo.forEach((question, number) => {
const quizSelectsWrap = quizSelects[number];
const userSelector = `input[name=select${number}]:checked`
const userAnswer = (quizSelectsWrap.querySelector(userSelector) || {}).value;
if(userAnswer == question.answerResult) {
quizView[number].classList.add("like")
quizView[number].classList.remove("dislike")
scoreCurrent++;
} else {
quizView[number].classList.add("dislike")
quizView[number].classList.remove("like")
const div = document.createElement("div");
quizSelectsWrap.appendChild(div).innerHTML = `${question.answerEx}
`
}
});
quizResult.innerHTML = `${quizInfo.length} 문제 중에 ${scoreCurrent} 문제를 맞추었습니다.`
}
document.querySelector(".quiz__confirm").addEventListener("click", answerQuiz);
>