Quiz

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
소스 보기
JAVASCRIPT
CSS
//선택자
    const quizWrap = document.querySelector(".quiz__wrap");

    // 문제 정보
    const quizInfo = [
        {
            infoDate: "17년 상시",
            infoType: "정보처리기능사",
            infoQuestion: "피변조파로부터 원래의 신호파를 만드는 것을 무엇이라 하는가?",
            infoChoice: ["발진", "정류", "증폭", "복조"],
            infoAnswer: "4",
            infoDesc: "피변조파는 변조된 신호를 의미합니다. 변조된 신호를 원래의 신호로 만드는 것을 복조라고 합니다.",
        },{
            infoDate: "17년 상시",
            infoType: "정보처리기능사",
            infoQuestion: "변,복조기의 역할과 거리가 먼 것은?",
            infoChoice: [
                "통신 신호의 변환기라고 볼 수 있다.",
                "디지털 신호를 아날로그 신호로 변환한다.",
                "공중 전화 통신망에 적합한 통신 신호로 변환한다.",
                "컴퓨터 신호를 광 케이블에 적합한 광 신호로 변환한다."
            ],
            infoAnswer: "4",
            infoDesc: "모뎀의 역할은 디지털 데이터를 아날로그 신호로 변조하고, 아날로그 신호를 디지털 데이터로 복조하는 역할을 한다. ",
        },
        {
            infoDate: "20년 2월",
            infoType: "정보처리기능사",
            infoQuestion: "인터넷 도메인 네임을 IP Address로 바꿔주는 시스템을 무엇이라 하는가?",
            infoChoice: [
                "HTTP",
                "TCP/IP",
                "URL",
                "DNS"
            ],
            infoAnswer: "4",
            infoDesc: "사람이 인식할 수 있는 도메인 네임을 컴퓨터가 이해할 수 있도록 숫자로 된 IP 주소로 변환할 때 사용하는 시스템은 DNS이다.",
        },
    ];

    let currentIndex = 0; // 현재 문제 변수 값(현제 풀고 있는 문제)
    //문제출력
    const updataQuiz = (index) => {
        let quizWrapTag = `
            
${quizInfo[index].infoDate} ${quizInfo[index].infoType}
${index + 1}.${quizInfo[index].infoQuestion}.
${quizInfo[index].infoAnswer}
${quizInfo[index].infoDesc}
`; quizWrap.innerHTML = quizWrapTag; // 선택자 const quizConfirm = quizWrap.querySelector(".quiz__confirm"); const quizNext = quizWrap.querySelector(".quiz__next"); // 정답 확인 버튼 quizConfirm.addEventListener("click",() => { const selectedChoice = quizWrap.querySelector("input[name='choice']:checked"); checkAnswer(); quizConfirm.classList.add("none"); // 정답 버튼 삭제 quizNext.classList.remove("none"); // 다음 버튼 추가 }); // 다음 문제 버튼 quizNext.addEventListener("click", () => { if(currentIndex //선택자 const quizWrap = document.querySelector(".quiz__wrap"); // 문제 정보 const quizInfo = [ { infoDate: "17년 상시", infoType: "정보처리기능사", infoQuestion: "피변조파로부터 원래의 신호파를 만드는 것을 무엇이라 하는가?", infoChoice: ["발진", "정류", "증폭", "복조"], infoAnswer: "4", infoDesc: "피변조파는 변조된 신호를 의미합니다. 변조된 신호를 원래의 신호로 만드는 것을 복조라고 합니다.", },{ infoDate: "17년 상시", infoType: "정보처리기능사", infoQuestion: "변,복조기의 역할과 거리가 먼 것은?", infoChoice: [ "통신 신호의 변환기라고 볼 수 있다.", "디지털 신호를 아날로그 신호로 변환한다.", "공중 전화 통신망에 적합한 통신 신호로 변환한다.", "컴퓨터 신호를 광 케이블에 적합한 광 신호로 변환한다." ], infoAnswer: "4", infoDesc: "모뎀의 역할은 디지털 데이터를 아날로그 신호로 변조하고, 아날로그 신호를 디지털 데이터로 복조하는 역할을 한다. ", }, { infoDate: "20년 2월", infoType: "정보처리기능사", infoQuestion: "인터넷 도메인 네임을 IP Address로 바꿔주는 시스템을 무엇이라 하는가?", infoChoice: [ "HTTP", "TCP/IP", "URL", "DNS" ], infoAnswer: "4", infoDesc: "사람이 인식할 수 있는 도메인 네임을 컴퓨터가 이해할 수 있도록 숫자로 된 IP 주소로 변환할 때 사용하는 시스템은 DNS이다.", }, ]; let currentIndex = 0; // 현재 문제 변수 값(현제 풀고 있는 문제) //문제출력 const updataQuiz = (index) => { let quizWrapTag = `
${quizInfo[index].infoDate} ${quizInfo[index].infoType}
${index + 1}.${quizInfo[index].infoQuestion}.
${quizInfo[index].infoAnswer}
${quizInfo[index].infoDesc}
`; quizWrap.innerHTML = quizWrapTag; // 선택자 const quizConfirm = quizWrap.querySelector(".quiz__confirm"); const quizNext = quizWrap.querySelector(".quiz__next"); // 정답 확인 버튼 quizConfirm.addEventListener("click",() => { const selectedChoice = quizWrap.querySelector("input[name='choice']:checked"); checkAnswer(); quizConfirm.classList.add("none"); // 정답 버튼 삭제 quizNext.classList.remove("none"); // 다음 버튼 추가 }); // 다음 문제 버튼 quizNext.addEventListener("click", () => { if(currentIndex < quizInfo.length -1){ quizNext.classList.add("none"); //다음 버튼 삭제 quizConfirm.classList.remove("none"); //정답 버튼 추가 currentIndex++; //문제 번호 추가 updataQuiz(currentIndex); // 퀴즈 반영 }else { alert("퀴즈가 종료되었습니다."); } }); } // 정답 확인 const checkAnswer = () => { const selectedChoice = quizWrap.querySelector("input[name='choice']:checked"); if (!selectedChoice) { alert("정답을 체크해주세요!"); // 정답을 체크하지 않았을 때 경고 메시지 } const userAnswer = selectedChoice.value; //사용자가 클릭한 정답 const correctAnswer = quizInfo[currentIndex].infoAnswer; //정답지의 정답 const quizElement = quizWrap.querySelector(".quiz"); const descElement = quizWrap.querySelector(".quiz__desc"); const answerElement = quizWrap.querySelector(".quiz__answer"); if(userAnswer === correctAnswer){ quizElement.classList.add("good"); } else { quizElement.classList.add("bad"); answerElement.classList.remove("none"); } descElement.classList.remove("none"); } //페이지가 로드된 후 document.addEventListener("DOMContentLoaded", () => { updataQuiz(currentIndex); }); quizInfo.length -1){ quizNext.classList.add("none"); //다음 버튼 삭제 quizConfirm.classList.remove("none"); //정답 버튼 추가 currentIndex++; //문제 번호 추가 updataQuiz(currentIndex); // 퀴즈 반영 }else { alert("퀴즈가 종료되었습니다."); } }); } // 정답 확인 const checkAnswer = () => { const selectedChoice = quizWrap.querySelector("input[name='choice']:checked"); if (!selectedChoice) { alert("정답을 체크해주세요!"); // 정답을 체크하지 않았을 때 경고 메시지 } const userAnswer = selectedChoice.value; //사용자가 클릭한 정답 const correctAnswer = quizInfo[currentIndex].infoAnswer; //정답지의 정답 const quizElement = quizWrap.querySelector(".quiz"); const descElement = quizWrap.querySelector(".quiz__desc"); const answerElement = quizWrap.querySelector(".quiz__answer"); if(userAnswer === correctAnswer){ quizElement.classList.add("good"); } else { quizElement.classList.add("bad"); answerElement.classList.remove("none"); } descElement.classList.remove("none"); } //페이지가 로드된 후 document.addEventListener("DOMContentLoaded", () => { updataQuiz(currentIndex); });
/* quiz__wrap */
    .quiz__wrap {
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        margin-top: 40px;
    }
    .quiz__wrap > .quiz {
        width: 500px;
        min-height: 400px;
        background-color: #fff;
        padding: 30px;
        border-radius: 20px;
        box-shadow: 2px 2px 2px rgba(0,0,0,0.1);
        margin: 10px;
    }
    .quiz__wrap > .quiz.good {
        position: relative;
    }
    .quiz__wrap > .quiz.good::before {
        content: '';
        width: 100px;
        height: 100px;
        border: 10px solid red;
        border-radius: 50%;
        position: absolute;
        left: 20px; 
        top: 20px;
        z-index: 100;
    }
    .quiz__wrap > .quiz.bad {
        position: relative;
    }
    .quiz__wrap > .quiz.bad::before {
        content: '';
        width: 150px;
        height: 10px;
        background-color: red;
        position: absolute;
        left: 0;
        top: 80px;
        border-radius: 30px;
        transform: rotate(45deg);
        z-index: 100;
    }
    .quiz__wrap > .quiz.bad::after {
        content: '';
        width: 150px;
        height: 10px;
        background-color: red;
        position: absolute;
        left: 0;
        top: 80px;
        border-radius: 30px;
        transform: rotate(-45deg);
        z-index: 100;
    }
    .quiz__header {
        margin-bottom: 20px;
        color: #696969;
    }
    .quiz__date {
        display: inline-block;
        margin-right: 5px;
        color: #696969;
    }
    .quiz__type {
        color: #696969;
    }
    .quiz__main {}
    .quiz__question {
        margin-bottom: 20px;
        font-size: 24px;
        font-weight: 400;
        line-height: 1.5;
    }
    .quiz__question em {
        font-size: 24px;
        font-style: normal;
        font-weight: 400;
    }
    .quiz__question span {
        font-size: 24px;
        line-height: 1.5;
        font-weight: 400;
    }
    .quiz__img {
        margin-bottom: 10px;
    }
    .quiz__img img {
        width: 100%;
        border: 1px solid #000;
    }
    .quiz__choice {
        margin-bottom: 20px;
    }
    .quiz__choice label {
        display: block;
        width: 100%;
    }
    .quiz__choice label input {
        position: absolute;
        clip: rect(0 0 0 0);
        width: 1px;
        height: 1px;
        margin: -1px;
        overflow: hidden;
    }
    .quiz__choice label span {
        position: relative;
        display: flex;
        align-items: center;
        border: 1px solid #eee;
        padding: 17px;
        margin-bottom: 10px;
        border-radius: 3px;
        font-size: 16px;
        line-height: 1.5;
        font-weight: 400;
        cursor: pointer;
    }
    .quiz__choice label span:hover {
        border-color: #412E91;
        color: #412E91;
        box-shadow: 1px 1px 5px #422e9160;
    }
    .quiz__choice label span::before {
        content: '';
        width: 24px;
        height: 24px;
        border-radius: 50%;
        flex-shrink: 0;
        box-shadow: inset 0 0 0 4px #412E91;
        margin-right: 15px;
        transition: all 0.3s;
    }
    .quiz__choice label input:checked + span::before {
        box-shadow: inset 0 0 0 9px #412E91;
    }
    .quiz__choice label input:checked + span {
        border-color: #412E91;
        color: #412E91;
        box-shadow: 1px 1px 5px #422e9160;
        background-color: #e9e4ff60;
    }
    .quiz__choice .choice {
        border: 1px solid #eee;
        padding: 17px 55px 17px 17px;
        margin-bottom: 5px;
        font-size: 16px;
        line-height: 1.5;
        transition: border-color 0.3s, background-color 0.3s;
        border-radius: 3px;
        color: #666;
    }
    .quiz__choice .choice:hover {
        border-color: #9378ff;
        background-color: #f6f4ff;
        cursor: pointer;
    }
    .quiz__choice .choice.correct {
        position: relative;
        border-color: #412E91;
        background-color: #e9e4ff60;
        color: #412E91;
        padding-right: 57px;
    }
    .quiz__choice .choice.correct::after {
        content: '';
        width: 14px;
        height: 14px;
        border: 6px solid #412e91;
        border-radius: 50%;
        position: absolute;
        right: 20px;
        top: 50%;
        transform: translateY(-50%);
    }
    .quiz__choice .choice.incorrect {
        position: relative;
        border-color: #912e3a;
        box-shadow: 1px 1px 5px #912e3a19;
        background-color: #912e3a19;
        color: #912e3a;
        padding-right: 57px;
    }
    .quiz__choice .choice.incorrect::before {
        content: '';
        position: absolute;
        right: 20px;
        top: 50%;
        transform: translateY(-50%);
        width: 28px;
        height: 6px;
        background-color: #912e3a;
        border-radius: 4px;
        transform: rotate(45deg);
        margin-top: -3px;
    }
    .quiz__choice .choice.incorrect::after {
        content: '';
        position: absolute;
        right: 20px;
        top: 50%;
        transform: translateY(-50%);
        width: 28px;
        height: 6px;
        background-color: #912e3a;
        border-radius: 4px;
        transform: rotate(-45deg);
        margin-top: -3px;
    }
    .quiz__animation {
        border: 1px dashed #b8a8ff;
        margin-bottom: 10px;
    }
    .quiz__input {
        margin-bottom: 10px;
    }
    .quiz__input input {
        width: 100%;
        padding: 20px;
        border: 1px solid #b8a8ff;
        border-radius: 3px;
    }
    .quiz__answer {
        background-color: #ede9ff;
        border: 1px solid #b8a8ff;
        padding: 20px;
        margin-bottom: 10px;
        line-height: 1.5;
        color: #666;
    }
    .quiz__answer::before {
        content: "👉 정답 : ";
    }
    .quiz__desc {
        border: 1px solid #eaeaea;
        padding: 20px;
        margin-bottom: 10px;
        line-height: 1.5;
        color: #666;
    }
    .quiz__desc::before {
        content: "👏 설명 : ";
    }
    .quiz__footer {}
    .quiz__confirm {    
        background-color: #412E91;
        color: #fff;
        text-align: center;
        padding: 20px;
        display: block;
        border: 0;
        width: 100%;
        transition: all 0.3s;
        border: 1px dashed transparent;
        border-radius: 3px;
    }
    .quiz__confirm:hover {
        border: 1px dashed #412E91;
        background-color: transparent;
        color: #412E91;
        cursor: pointer;
    }
    .quiz__next {
        width: 100%;
        border: 1px dashed #412E91;
        padding: 10px 20px;
        background-color: #fff;
        cursor: pointer;
        color: #412E91;
        transition: all 0.3s;
    }
    .quiz__next:hover {
        background-color: #f5f2ff;;
    }
    .quiz__indicator {
        background-color: #f5f2ff;
        padding: 20px;
        border-radius: 3px;
        margin-bottom: 20px;
    }
    .quiz__indicator span {
        display: inline-block;
        width: 20px;
        height: 20px;
        border: 1px solid #412e91;
        box-shadow: 1px 1px #412e91;
    }
    .quiz__indicator span.correct {
        background-color: #412E91;
        position: relative;
    }
    .quiz__indicator span.correct::before {
        content: '';
        width: 8px;
        height: 8px;
        border: 4px solid #fff;
        border-radius: 50%;
        position: absolute;
        left: 1px;
        top: 1px;
    }
    .quiz__indicator span.incorrect {
        position: relative;
    }
    .quiz__indicator span.incorrect::before {
        content: '';
        position: absolute;
        left: 2px;
        top: 7px;
        width: 14px;
        height: 4px;
        border-radius: 4px;
        background-color: #412E91;
        transform: rotate(-45deg);
    }
    .quiz__indicator span.incorrect::after {
        content: '';
        position: absolute;
        left: 2px;
        top: 7px;
        width: 14px;
        height: 4px;
        border-radius: 4px;
        background-color: #412E91;
        transform: rotate(45deg);
    }
    .quiz__check{
        position: fixed;
        right: 20px;
        bottom: 20px;
        width: 100px;
        height: 100px;
        background-color: #412E91;
        color: #fff;
        border-radius: 50%;
        text-align: center;
        line-height: 100px;
        cursor: pointer;
        transition: all 0.3s;
        border: 1px dashed transparent;
    }
    .quiz__check:hover{
        background-color: #e1d9ff;
        border: 1px dahsed #412e91;
        color: #412e91;
    }    
    @media (max-width: 600px){
        #header {
            flex-direction: column;
        }
        #header h1 a{
            padding: 15px;
        }
        #header h1 nav{
            padding-right: 0;
            padding: 15px;
        }
    
        #header nav li a {
            width: 30px;
            height: 30px;
            padding: 7px;
        }
        .quiz__wrap {
            padding: 0 6px;
            margin-top: 0;
        }
        .quiz__wrap > .quiz {
            width: 100%;
            padding: 30px 20px;
        }
        .quiz__header {
            margin-bottom: 20px;
            font-size: 14px;
        }
        .quiz__date {
            font-size: 14px;
        }
        .quiz__type {
            font-size: 14px;
        }
        .quiz__question {
            margin-bottom: 20px;
            line-height: 1.5;
            font-size: 20px;
        }
        .quiz__question em {
            font-size: 20px;
        }
        .quiz__question span {
            font-size: 20px;       
        }
        .quiz__input input {
            padding: 14px;
        }
        .quiz__answer {
            padding: 14px;
        }
        .quiz__desc {
            padding: 14px;
        }
        .quiz__choice label span {
            padding : 13px;
        }
        .quiz__confirm {
            padding:  13px;
        }
    }  
X
audgns722@naver.com