정답입니다!
틀렸습니다!
const quizQuestion = document.querySelector(".quiz__question"); //문제 번호, 질문
const quizSelects = document.querySelector(".quiz__selects")
const quizType = document.querySelector(".quiz__type") //연도
const quizResult = document.querySelector(".quiz__answer .result") //해설
const quizConfirm = document.querySelector(".quiz__answer .confirm"); //정답확인버튼
const quizView = document.querySelector(".quiz__view"); //강아지
let quizCount = 0;
let quizScore = 0;
//문제 출력
const updateQuiz = (index) => {
const questionTag = `
<span class="number">${quizInfo[index].answerNum}</span>
<div class="ask">${quizInfo[index].answerAsk}</div>
`;
const choiceTag = `
<label for="select1">
<input type="radio" id="select1" class="select" name="select" value="1">
<span class="choice">${quizInfo[index].answerChoice[0]}</span>
</label>
<label for="select2">
<input type="radio" id="select2" class="select" name="select" value="2">
<span class="choice">${quizInfo[index].answerChoice[1]}</span>
</label>
<label for="select3">
<input type="radio" id="select3" class="select" name="select" value="3">
<span class="choice">${quizInfo[index].answerChoice[2]}</span>
</label>
<label for="select4">
<input type="radio" id="select4" class="select" name="select" value="4">
<span class="choice">${quizInfo[index].answerChoice[3]}</span>
</label>
`;
//선택자
quizQuestion.innerHTML = questionTag; //번호, 질문
quizSelects.innerHTML = choiceTag; //객관식
quizType.innerHTML = quizInfo[index].answerType; //객관식
quizResult.innerHTML = quizInfo[index].answerEx; //해설
const quizChoice = quizSelects.querySelectorAll(".choice");
for(let i=0; i<quizChoice.length; i++){
quizChoice[i].setAttribute("onclick", "choiceSelected(this)")
}
//문제, 해설 숨기기
quizResult.style.display = "none";
quizConfirm.style.display = "none";
}
updateQuiz(quizCount);
const choiceSelected = (answer) => { //클릭한 텍스트가 들어와있다.
let userAnswer = answer.textContent; //사용자가 체크한 정답
let currentAnswer = quizInfo[quizCount].answerResult; //문제 정답
if(userAnswer == currentAnswer) {
console.log("정답");
quizView.classList.add("like")
quizScore++
} else {
console.log("오답");
quizView.classList.add("dislike")
quizResult.style.display = "block";
}
quizConfirm.style.display = "block";
}
const answerQuiz = () => {
if(quizInfo.length -1 == quizCount) {
quizConfirm.textContent = `총 ${quizInfo.length} 문제 중에 ${quizScore} 문제를 맞추었습니다.`
};
quizCount++;
updateQuiz(quizCount);
quizView.classList.remove("like", "dislike");
}
quizConfirm.addEventListener("click", answerQuiz);
/* modal__wrap */
.modal__wrap{
}
.modal__wrap .modal__btn {
border: 2px solid #f5f5;
padding: 10px 20px;
border-radius: 50px;
position: absolute;
bottom: 50px;
right: 10px;
transition: all 0.5s ease-in-out;
cursor: pointer;
display: inline-block;
}
.modal__wrap .modal__btn:hover {
background-color: rgb(72, 208, 190);
}
.modal__cont {
width: 100%;
height: 100vh;
background-color: #f5f5;
position: fixed;
top: -40px;
left: 0;
display: flex;
align-items: center;
overflow-x: hidden;
transform: scale(0);
z-index: 1000;
}
.modal__cont .modal__box {
width: 70%;
height: 70vh;
margin: 0 auto;
background-color: rgba(255, 255, 255, 0.456);
border-radius: 0.5rem;
box-shadow: 0 10px 20px -5px hsl(180deg 2% 10%);
transform: scale(0);
}
.title {
background-color: rgba(10, 178, 255, 0.333);
border-top-left-radius: 0.5rem;
border-top-right-radius: 0.5rem;
display: flex;
align-items: center;
height: 50px;
justify-content: space-between;
}
.title .dot {
width: 15px;
height: 15px;
border: 1px solid #ff0000;
border-radius: 50%;
display: inline-block;
background-color: #ff0000;
position: relative;
}
.title .dot::before{
content: '';
width: 15px;
height: 15px;
border: 1px solid #00fc60;
border-radius: 50%;
display: inline-block;
background-color: #00fc60;
position: absolute;
left: 50px;
}
.title .dot:after {
content: '';
width: 15px;
height: 15px;
border: 1px solid #ffff00;
border-radius: 50%;
display: inline-block;
background-color: #ffff00;
position: absolute;
left: 25px;
}
.tabs {
display: flex;
}
.tabs > div {
color: #7A7D9D;
background-color: #1f224a;
padding: 0.35rem 0.8rem 0.25rem 0.8rem;
margin-right: 0.5rem;
display: flex;
align-items: center;
border-radius: 0.4rem;
text-transform: uppercase;
cursor: grab;
}
.tabs > div.active {
background-color: #fff;
}
.title .plus {
border: 1px solid #000;
padding: 0.4rem;
border-radius: 10px;
background-color: #1f224a;
color: #fff;
}
.modal__box .title .tabs > div.active {
background-color: #fff;
}
.modal__box .title .tabs > div em {
font-style: normal;
}
.modal__box .title .tabs > div .favicon {
margin-right: 0.4rem;
margin-top: 0.2rem;
}
.modal__box .title .tabs > div .close {
margin-left: 4rem;
}
.modal__box .cont {
background-color: #282936;
height: 100%;
box-sizing: border-box;
border-bottom-left-radius: 0.5rem;
border-bottom-right-radius: 0.5rem;
overflow-y: auto;
}
.modal__box .cont > div{
display: none;
}
.modal__box .cont > div.active {
display: block;
height: 100%;
}
.modal__cont .modal__close {
border: 1px solid #000;
position: absolute;
right: 20px;
top: 100px;
padding: 10px 20px;
border-radius: 50px;
background-color: #f5f5;
transition: all 0.5s ease;
}
.modal__cont .modal__close:hover {
background-color: #fff;
}
.modal__close {
position: absolute;
right: 10px;
top: 10px;
background-color: #1f224a;
padding: 1rem 1rem 0.8rem 1rem;
border-radius: 5px;
box-shadow: 0 3px 5px -5px hsl(180deg 2% 10%);
cursor: pointer;
transition: all 0.3s;
opacity: 0;
}
.modal__close:hover{
background-color: #13142d7d;
}
.modal__close svg{
color: #fff;
}
/* 모달 애니메이션 */
.modal__cont.show { /*전체 배경*/
animation: foldOut 1s ease forwards;
}
.modal__cont.show .modal__box { /*스크립트 배경*/
animation: zoomOut 0.5s 1s ease forwards; /*초를 두개써서딜레이를 줄 수 있다*/
}
.modal__cont.show .modal__close { /* 닫기버튼*/
animation: closeOut 0.6s 1.5s ease forwards;
}
.modal__cont.show.hide {
animation: foldIn 0.3s 0.3s ease backwards;
}
.modal__cont.show.hide .modal__box{
animation: zoomIn 0.5s 1s ease backwards;
}
.modal__cont.show.hide .modal__close { /* 닫기버튼*/
animation: closeIn 0.3s 0.6s ease backwards;
opacity: 0;
}
@keyframes foldOut {
0% {transform: scaleX(0) scaleY(0.001);}
50% {transform: scaleX(1) scaleY(0.001);}
100% {transform: scaleX(1) scaleY(1);}
}
@keyframes closeOut {
0% {opacity: 0;}
100% {opacity: 1;}
}
@keyframes foldIn {
0% {transform: scaleX(1) scaleY(1);}
50% {transform: scaleX(1) scaleY(0.001);}
100% {transform: scaleX(0) scaleY(0.001);}
}
@keyframes zoomOut {
0% {transform: scale(0);}
100% {transform: scale(1);}
}
@keyframes zoomIn {
100% {transform: scale(1);}
0% {transform: scale(0);}
}
<!-- 01. 퀴즈 이펙트 - 정답 확인하기 -->
<!-- 02. 퀴즈 이펙트 - 주관식 확인하기 -->
<!-- 03. 퀴즈 이펙트 - 주관식 (여러문제) 확인하기 -->
<!-- 04. 퀴즈 이펙트 - 객관식 확인하기 -->
<!-- 05. 퀴즈 이펙트 - 객관식 (여러문제) 결과 확인하기 -->
<!-- 06. 퀴즈 이펙트 - 객관식 (여러문제) 슬라이드 확인하기 -->
<div class="quiz__answer">
<div class="quiz__selects">
<label for="select1">
<input type="radio" id="select1" class="select" name="select" value="1">
<span class="choice"></span>
</label>
<label for="select2">
<input type="radio" id="select2" class="select" name="select" value="2">
<span class="choice"></span>
</label>
<label for="select3">
<input type="radio" id="select3" class="select" name="select" value="3">
<span class="choice"></span>
</label>
<label for="select4">
<input type="radio" id="select4" class="select" name="select" value="4">
<span class="choice"></span>
</label>
</div>
<button class="confirm">정답 확인하기</button>
<div class="result"></div>
</div>