<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">
<input class="quiz__input" type="text" placeholder="정답을 적어주세요!">
<button class="quiz__confirm">정답 확인하기</button>
<div class="quiz__result"></div>
</div>
</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: 2px;
width: 15px;
height: 15px;
border: 6px ridge #cacaca;
}
.quiz__type::after {
content: '';
position: absolute;
right: 2px;
top: 2px;
width: 15px;
height: 15px;
border: 6px ridge #cacaca;
}
.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-color: #f5f5f5;
position: relative;
}
.quiz__view .true {
position: absolute;
left: 70%;
top: 100px;
width: 120px;
height: 120px;
border-radius: 50%;
z-index: 100;
line-height: 120px;
text-align: center;
color: #fff;
background-color: #F5534F;
opacity: 0;
}
.quiz__view .false {
position: absolute;
right: 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__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;
font-family: 'Cafe24Dangdanghae';
text-shadow: 1px 1px 1px #fff;
transition: all 0.3s;
cursor: pointer;
}
.quiz__confirm:hover {
background: #b3b3b3;
}
.quiz__result {
text-align: center;
border: 6px ridge #cacaca;
width: 100%;
font-size: 22px;
padding: 13px 20px;
background: #fff;
font-family: 'Cafe24Dangdanghae';
text-shadow: 1px 1px 1px #fff;
/* display: none; */
}
.quiz__input {
width: 100%;
border: 6px ridge #cacaca;
font-size: 22px;
padding: 13px 20px;
background: #fff;
font-family: 'Cafe24Dangdanghae';
text-shadow: 1px 1px 1px #fff;
margin-bottom: 10px;
}
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 quizInput = document.querySelector(".quiz__input"); //input
//문제 정보
const answerType = "javascript";
const answerNum = 1;
const answerAsk = "객체 기반의 스크립트 프로그래밍 언어는 무엇입니까?";
const answerResult = "javascript";
//문제 출력
quizType.textContent = answerType;
quizNumber.textContent = answerNum + ". ";
quizAsk.textContent = answerAsk;
quizResult.textContent = `정답은 : ${answerResult} 입니다.`;
//정답숨기기
quizResult.style.display = "none";
//정답 확인 클릭 시
quizConfirm.addEventListener("click", () => {
quizConfirm.style.display = "none"; //정답 확인 버튼 사라짐
quizResult.style.display = "block"; //정답 나타내기
const userWord = quizInput.value.toLowerCase().trim(); //사용자 데이터 읽어옴
quizInput.style.display = "none"; //확인 버튼 클릭 시 input 사라짐
//사용자 데이터 == 정답
if (userWord == answerResult) { //사용자 데이터와 정답 비교
quizView.classList.add("like"); //같으면 quizView에 클래스like를 주어 강아지 like애니메이션
} else {
quizView.classList.add("dislike");//다르면 quizView에 클래스dislike를 주어 강아지 dislike애니메이션
}
});