728x90
๋ฐ์ํ
๊ฐ๊ด์ ์ฌ๋ฌ๋ฌธ์
์๋ฐ์คํฌ๋ฆฝํธ
const quizWrap = document.querySelector(".quiz__wrap");
const quizScore = 0;
const quizConfirm = document.querySelector(".quiz__confirm .check")
//๋ฌธ์ ์ถ๋ ฅ
const updateQuiz = () => {
const exam = [];
quizInfo.forEach((question, number) => {
exam.push(`<div class="quiz">
<span class="quiz__type">${question.answerType}</span>
<h2 class="quiz__question">
<span class="number">${question.answerNum}. </span>
<div class="ask">${question.answerAsk}
</div>
</h2>
<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${number}">
<input type="radio" id="select1${number}" class="select" name="select${number}" value="1">
<span class="choice">${question.answerChoice[1]}</span>
</label>
<label for="select2${number}">
<input type="radio" id="select2${number}" class="select" name="select${number}" value="2">
<span class="choice">${question.answerChoice[2]}</span>
</label>
<label for="select3${number}">
<input type="radio" id="select3${number}" class="select" name="select${number}" value="3">
<span class="choice">${question.answerChoice[3]}</span>
</label>
<label for="select4${number}">
<input type="radio" id="select4${number}" class="select" name="select${number}" value="4">
<span class="choice">${question.answerChoice[4]}</span>
</label>
</div>
</div>
</div>`);
});
exam.push(`
<div class="quiz__confirm">
<button class="check">์ ๋ต ํ์ธํ๊ธฐ</button>
<div class="ex"></div>
<div>
`)
quizWrap.innerHTML = exam.join('');
}
updateQuiz();
//์ ๋ต ํ์ธ
const answerQuiz = () => {
const quizSelects = document.querySelectorAll(".quiz__selects"); //๊ฐ๊ด์ ๋ณด๊ธฐ
const quizConfirm = document.querySelector(".quiz__confirm .check");
//์ฌ์ฉ์๊ฐ ์ฒดํฌํ ๋ณด๊ธฐ == ๋ฌธ์ ์ ๋ต
quizInfo.forEach((question, number) => {
const userSelector = `input[name=select${number}]:checked`; //์ฌ์ฉ์๊ฐ ์ฒดํฌํ ๋ณด๊ธฐ
const quizSelectsWrap = quizSelects[number];
const userAnswer = (quizSelectsWrap.querySelector(userSelector) || {}).value;
const quizView = document.querySelectorAll(".quiz__view"); // ๊ฐ์์ง
if (userAnswer == question.answerResult) {
console.log("์ ๋ต")
quizView[number].classList.add("like");
quizScore++;
} else {
console.log("์ค๋ต")
quizView[number].classList.add("dislike");
const divBox = document.createElement("div");
quizSelectsWrap.appendChild(divBox).innerHTML = `<p class="result">${question.answerEx}</p>`
}
});
document.querySelector(".quiz__confirm .check").innerHTML = `${quizScore < 36 ? quizInfo.length + "/" + quizScore + " ๋ถํฉ๊ฒฉ์
๋๋ค. ๋ ๊ณต๋ถํ์ธ์!" : quizInfo.lenght + "/" + quizScore + "์ถํํฉ๋๋ค ํฉ๊ฒฉ์
๋๋ค!"}`;
// //์ ์์ ํฉ๋ถํฉ
// document.querySelector("quiz__confirm.ex").innerHTML = `${quizScore < 36 ? quizInfo.length + "/" + quizScore +" ๋ถํฉ๊ฒฉ์
๋๋ค. ๋ ๊ณต๋ถํ์ธ์!" : quizInfo.lenght + "/" + quizScore + "์ถํํฉ๋๋ค ํฉ๊ฒฉ์
๋๋ค!"}`;
// quizConfirm.textContent = `์ด ${quizInfo.length} ๋ฌธ์ ์ค์ ${quizScore} ๋ฌธ์ ๋ฅผ ๋ง์ถ์์ต๋๋ค.`
//์ ์ฒด ๋ฌธ์ ์
console.log(quizInfo.length);
//๋ด๊ฐ ๋งํ ์
console.log(quizScore.length);
}
//์ ๋ต ํด๋ฆญ
document.querySelector(".quiz__confirm .check").addEventListener("click", answerQuiz);
728x90
๋ฐ์ํ
'์ดํํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
2. ์์น ์ดํํธ - 2 (2) | 2022.08.17 |
---|---|
2. ์์น ์ดํํธ -1 (1) | 2022.08.17 |
ํด์ฆ ์ดํํธ - ๊ฐ๊ด์ ์ ํ (6) | 2022.08.08 |
ํด์ฆ ์ดํํธ - ์ฃผ๊ด์ ์ฌ๋ฌ ์ ํ (6) | 2022.08.06 |
ํด์ฆ ์ดํํธ - ์ฃผ๊ด์ (11) | 2022.08.04 |
๋๊ธ