728x90
๋ฐ์ํ

โญ๏ธ ๊ฐ๊ด์ ๋ค์ ๋ฌธํญ (์ ๋ต ๊ฐฏ์ / ํฉ๊ฒฉ ์ฌ๋ถ ํ์ธ) โญ๏ธ
01. ๋ง๋๋ ์์
1) ์ถ๋ ฅํ ๋ด์ฉ์ด ๋ค์ด์๋ ์์ ์ ํํ๊ธฐ
2) ์ง๋ฌธ๊ณผ ์ ๋ต ๋ด์ฉ, ํ์ํ ๊ฐ ์
๋ ฅํ๊ธฐ
3) ์ง๋ฌธ ๋ด์ฉ ์ถ๋ ฅํ๊ธฐ
4) ์ ๋ต ๋ด์ฉ ์จ๊ฒจ๋๊ธฐ
5) ์ ๋ต ํ์ธ ๋ฐ ๊ฒฐ๊ณผ๊ฐ ์ค์ ํ๊ธฐ
6) ์ ๋ต ๋ฒํผ์ ๋์ ์ค์ ํ๊ธฐ
02. < script > ์ ์์ฑํ๊ธฐ
// ๋ฌธ์ ์ ๋ณด const quizInfo = [ { answerType: "์น ๋์์ธ ๊ธฐ๋ฅ์ฌ (2014๋
01ํ)", answerNum: "1", answerAsk: "๋ค์์ ๋์์ธ ์๋ฆฌ ์ค ๋ฆฌ๋ฌ์ ํด๋น๋์ง ์๋ ๊ฒ์?", answerChoice: [ "์ ์ด", "๊ฐ์กฐ", "๊ท ์ผ", "์ ์ฆ", ], answerResult: "๊ท ์ผ", answerEx: "๊ท ์ผ // '๋ฆฌ๋ฌ(์จ๋)'์ ๊ฐ ๋ถ๋ถ ์ฌ์ด์ ์๊ฐ์ ์ธ ๊ฐํ ํ๊ณผ ์ฝํ ํ์ด ๊ท์น์ ์ผ๋ก ์ฐ์๋ ๋ ์๊ธฐ๋ ๋์์ธ์ ์๋ฆฌ๋ฅผ ๋งํฉ๋๋ค. '๊ท ์ผ'์ ๋ถํผ, ์ฆ๋ ๋ฑ ๋ฌผ๋ฆฌ์ ๊ตฌ์กฐ์ ์์ฑ์์ ์๊ฐ์ ์ธ ์์ ๊ฐ์ ์ด๋ฃจ๋ ๊ฒ์ด๋ฉฐ, ๋ฆฌ๋ฌ์ ํด๋น๋์ง ์์ต๋๋ค.", // ์ ๋ต ํด์ค }, { answerType: "์น ๋์์ธ ๊ธฐ๋ฅ์ฌ (2014๋
01ํ)", answerNum: "2", answerAsk: "ํด์์ ์๋ ์กฐ์ฝ๋์ ์์ฐ์ ํ์ ์ํด ํ์ฐ์ ์ผ๋ก ๋ง๋ค์ด์ง ํํ๋ผ๋ ์์ฐ์ ๋ฒ์น์ด ๋ง๋ ์์ฐ์ ํํ๋ฅผ ์ฃผ์ฅํ ์ฌ๋์?", answerChoice: [ "๋ฅด ์ฝ๋ฅด๋ท์ง์", "ํํ๋ฅ", "์๋ฅธํ์", "๋ชจํ๋ก๋๊ธฐ", ], answerResult: "๋ชจํ๋ก๋๊ธฐ", answerEx: "๋ชจํ๋ก๋๊ธฐ // ๋ชจํ๋ก๋๊ธฐ์ ์ฌ์์์ ์ง๋ฌธ๋ด์ฉ์ ๋ํ ์ ๋ณด๋ฅผ ๋์ ํ ๋ชป์ฐพ๊ฒ ์ต๋๋ค. 'ํด์์ ์๋ ๋ฌด์ธ๋์์ ํ๋ก๋๊ธฐ'๋ผ๊ณ '๋ชจํ๋ก๋๊ธฐ'๋ฅผ ๊ธฐ์ตํด์ฃผ์ธ์ :) ", }, // ...(์๋ต)...์ด์ด์ ๊ณ์ ์์ฑํฉ๋๋ค. // ๋ฌธ์ ์ ๋ณด (์ ํ์) const quizType = document.querySelector(".quiz__type"); // ๋ฌธ์ ์ ํ const quizQuestion = document.querySelector(".quiz__question"); // ๋ฌธ์ ๋ฒํธ, ์ง๋ฌธ const querySelects = document.querySelector(".quiz__selects"); // ๊ฐ๊ด์ ๋ณด๊ธฐ 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> `; // ๋ฌธ์ ์ถ๋ ฅ quizType.innerHTML = quizInfo[index].answerType; // ํด์ฆ ์ ํ ์ถ๋ ฅ quizQuestion.innerHTML = questionTag; // ๋ฒํธ์ ์ง๋ฌธ ์ถ๋ ฅ querySelects.innerHTML = choiceTag; // ๊ฐ๊ด์ ๋ณด๊ธฐ ์ถ๋ ฅ quizResult.innerHTML = quizInfo[index].answerEx; // ํด์ค ์ถ๋ ฅ // ์ ๋ต ํ์ธ ์ ํ์ (์์ชฝ์ ์ ์ ์ ์์ด์ ์๋์ ์ ์ด์ค) const quizChoice = querySelects.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) => { // alert(answer.textContent); ์ฌ์ฉ์๊ฐ ํด๋ฆญํ ๋ต์ ์ฐฝ ๋ฉ์์ง๋ก ๋์์ค let userAnswer = answer.textContent; // ์ฌ์ฉ์๊ฐ ์ฒดํฌํ ์ ๋ต let currentAnswer = quizInfo[quizCount].answerResult; // ๋ฌธ์ ์ ๋ต if(userAnswer == currentAnswer){ quizScore++; console.log("์ ๋ต") quizView.classList.add("like") } 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} ๋ฌธ์ ๋ฅผ ๋ง์ถ๊ณ , ${quizInfo.length - quizScore} ๋ฌธ์ ๋ฅผ ํ๋ ธ์ต๋๋ค. ` if(quizScore >= 2){ quizConfirm.textContent += "๐์ถํํฉ๋๋ค. ํฉ๊ฒฉ๐"; } else { quizConfirm.textContent += "๐ค๐พ์กฐ๊ธ๋ง ๋ ํ๋ด์ธ์. ๋ถํฉ๊ฒฉ๐ง"; } } quizCount++; updateQuiz(quizCount); quizView.classList.remove("like","dislike") } quizConfirm.addEventListener("click", answerQuiz);
03. ๊ฒฐ๊ณผ๋ณด๊ธฐ
728x90
๋ฐ์ํ
'Javascript > Effect' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ฌ๋ผ์ด๋ ์ดํํธ (2) (3) | 2022.08.29 |
---|---|
์ฌ๋ผ์ด๋ ์ดํํธ (1) (3) | 2022.08.29 |
search Effect (3) (6) | 2022.08.23 |
search Effect (2) (3) | 2022.08.18 |
search Effect (1) (2) | 2022.08.18 |
๋๊ธ