<div class="quiz__wrap">
<div class="quiz">
<h2 class="quiz__Type"></h2>
<h3 class="quiz__question">
<span class="quiz__number"></span>
<span class="quiz__ask"></span>
</h3>
<div class="quiz__view">
<div class="true">정답입니다.</div>
<div class="false">틀렸습니다.</div>
<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 class="quiz__answer">
<div class="quiz__selects">
<label for="select1">
<input class="select" type="radio" id="select1" name="select" value="1">
<span class="choice"></span>
</label>
<label for="select2">
<input class="select" type="radio" id="select2" name="select" value="2">
<span class="choice"></span>
</label>
<label for="select3">
<input class="select" type="radio" id="select3" name="select" value="3">
<span class="choice"></span>
</label>
<label for="select4">
<input class="select" type="radio" id="select4" name="select" value="4">
<span class="choice"></span>
</label>
</div>
<button class="quiz__confirm">정답 확인하기</button>
<div class="quiz__result"></div>
</div>
</div>
</div>
/* quiz__wrap */
.quiz__wrap {
display: flex;
align-items: center;
justify-content: center;
margin-top: 150px;
}
.quiz {
max-width: 500px;
width: 100%;
background: #fff;
border: 8px ridge #cacaca;
flex-wrap: wrap;
margin: 10px;
}
.quiz__Type {
background: #cacaca;
text-align: center;
font-size: 14px;
color: #3b3b3b;
border: 3px ridge #cacaca;
padding: 3px 0;
position: relative;
}
.quiz__question {
border-top: 6px ridge #cacaca;
border-bottom: 6px ridge #cacaca;
padding: 13px 30px;
font-size: 24px;
line-height: 1.4
}
.quiz__Type::before {
content: '';
position: absolute;
left: 2px;
top: 2px;
width: 5px;
height: 5px;
border: 6px ridge #cacaca;
}
.quiz__Type::after {
content: '';
position: absolute;
right: 2px;
top: 2px;
width: 5px;
height: 5px;
border: 6px ridge #cacaca;
}
.quiz__number {
font-family: 'Cafe24Dangdanghae';
color: #bababa;
}
.quiz__ask {
font-family: 'Cafe24Dangdanghae';
}
.quiz__view {
background-color: #f5f5f5;
position: relative;
}
.quiz__view .true {
position: absolute;
left: 70%;
top: 100px;
width: 100px;
height: 100px;
background: #f5534f;
border-radius: 50%;
z-index: 100;
line-height: 100px;
text-align: center;
color: #fff;
opacity: 0;
}
.quiz__view .false {
position: absolute;
right: 70%;
top: 100px;
width: 100px;
height: 100px;
background: #fff;
border-radius: 50%;
z-index: 100;
line-height: 100px;
text-align: center;
color: #f5534f;
opacity: 0;
}
.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__answer {
background-color: #f5f5f5;
border-top: 6px ridge #cacaca;
padding: 10px;
}
.quiz__confirm {
border: 6px ridge #cacaca;
width: 100%;
font-size: 22px;
padding: 13px 20px;
background: #d6d6d6;
text-shadow: 1px 1px 1px #fff;
transition: all 0.3s;
cursor: pointer;
}
.quiz__confirm:hover {
background: #b3b3b3;
}
.quiz__result {
border: 6px ridge #cacaca;
width: 100%;
font-size: 22px;
padding: 13px 20px;
background: #fff;
text-align: center;
text-shadow: 1px 1px 1px #fff;
font-family: 'Cafe24Dangdanghae';
line-height: 1.4;
}
.quiz__input {
border: 6px ridge #cacaca;
width: 100%;
font-size: 22px;
padding: 13px 20px;
background: #fff;
text-align: left;
text-shadow: 1px 1px 1px #fff;
font-family: 'Cafe24Dangdanghae';
margin-bottom: 10px;
}
.quiz__selects {
margin-top: 20px;
margin-bottom: 15px;
}
.quiz__selects label {
display: flex;
}
.quiz__selects label input {
position: absolute;
left: -9999px;
}
.quiz__selects label span {
font-size: 20px;
line-height: 1.3;
padding: 10px 30px 10px 20px;
margin: 3px 0;
border-radius: 5px;
font-family: 'Cafe24Dangdanghae';
display: flex;
align-items: center;
cursor: pointer;
transition: all 0.25s;
}
.quiz__selects label span::before {
content: '';
width: 30px;
height: 30px;
border-radius: 50%;
margin-right: 15px;
background: #fff;
display: flex;
flex-shrink: 0;
box-shadow: inset 0 0 0 4px #64a30b;
transition: all 0.25s;
}
.quiz__selects label input:checked + span {
background-color: #f5ffe7;
}
.quiz__selects label input:checked + span::before {
box-shadow: inset 0 0 0 10px #64a30b;
}
<script>
const quizType = document.querySelector(".quiz__Type"); //문제 유형
const quizNumber = document.querySelector(".quiz__number"); //문제 번호
const quizAsk = document.querySelector(".quiz__ask"); //문제 질문
const quizConfirm = document.querySelector(".quiz__confirm"); //문제 정답 버튼
const quizResult = document.querySelector(".quiz__result"); //문제 설명
const quizView = document.querySelector(".quiz__view"); //문제 화면
const quizSelects = document.querySelector(".quiz__selects"); //객관식 보기
const quizChoice = quizSelects.querySelectorAll(".choice"); //객관식 보기
const quizSelect = quizSelects.querySelectorAll(".select"); //객관식 보기
//문제 정보
const quizInfo = [
{
answerType : "javascript",
answerNum : 1,
answerAsk : "객체 기반의 스크립트 프로그래밍 언어는 무엇입니까?",
answerChoice : ["javascript", "html", "css", "jquery"],
answerResult : "1",
answerEx : "객체 기반의 스크립트 프로그래밍 언어는 자바스크립트입니다."
}
];
//문제 출력
function updateQuiz(){
quizType.textContent = quizInfo[0].answerType;
quizNumber.textContent = quizInfo[0].answerNum;
quizAsk.textContent = quizInfo[0].answerAsk;
quizResult.textContent = quizInfo[0].answerEx;
for(let i=0; i<4; i++){
quizChoice[i].textContent = quizInfo[0].answerChoice[i];
}
//설명 감추기
quizResult.style.display = "none";
}
updateQuiz();
//정답 확인
function answerQuiz(){
//사용자가 클릭한 input --> checked : 사용자가 선택한 정답 == 객체 안에 정답
for(let i=0; i<quizSelect.length; i++){
if(quizSelect[i].checked == true){ //사용자가 무엇을 체크했는지 확인
if(quizSelect[i].value == quizInfo[0].answerResult){
//정답일때
quizView.classList.add("like");
quizConfirm.style.display = "none";
} else {
//오답일때
quizView.classList.add("dislike");
quizConfirm.style.display = "none";
quizResult.style.display = "block"
}
}
}
}
quizConfirm.addEventListener("click", (answerQuiz))
</script>