Quiz

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
소스 보기
JAVASCRIPT
CSS
//선택자
    const quizWrap = document.querySelector(".quiz__wrap");
     
    // 문제 정보
    const quizInfo = [
         {
             infoDate : "2006년 5회",
             infoType : "정보처리 기능사",
             infoQuestion : "이항(binary) 연산에 해당하는 것은?",
             infoChoice : {
                 1: "COMPLEMENT",
                 2: "AND",
                 3: "ROTATE",
                 4: "SHIFT"
             },
             infoAnswer : "2",
             infoDesc : "단항연산 : ROTATE, SHIFT, MOVE, NOT(COMPLEMENT)"
         },{
             infoDate : "2006년 5회",
             infoType : "정보처리 기능사",
             infoQuestion : "프로그램이 컴퓨터의 기종에 관계없이 수행될 수 있는 성질을 의미하는 것은?",
             infoChoice : {
                 1: "가용성",
                 2: "신뢰성",
                 3: "호환성",
                 4: "안전성"
             },
             infoAnswer : "3",
             infoDesc : "컴퓨터의 기종에 관계없이 동작하므로 호환성입니다. 호환성이란 까스활명수, 까스명수, 베아제등 이름은 틀리지만 소화제의 기능을 하는것처럼 기종에 관계없이 동작할수 있는 것들을 말합니다."
         },{
             infoDate : "2006년 5회",
             infoType : "정보처리 기능사",
             infoQuestion : "제어장치가 앞의 명령 실행을 완료한 후, 다음에 실행 할 명령을 기억장치로부터 가져오는 동작을 완료할 때까지의 주기를 무엇이라고 하는가?",
             infoChoice : {
                 1: "fetch cycle",
                 2: "transfer cycle",
                 3: "search time",
                 4: "run time"
             },
             infoAnswer : "1",
             infoDesc : "명령어를 가지고 오는것을 fetch cycle 이라고 합니다."
         }
     ];
     // 문제출력
     const updataQuiz = () => {
         const quizArray = [];

         quizInfo.forEach((quiz, index) => {
             quizArray.push(`
                 
${quiz.infoDate} ${quiz.infoType}
${index+1}. ${quiz.infoQuestion}
${quiz.infoAnswer}
${quiz.infoDesc}
` ); }); quizWrap.innerHTML = quizArray.join(""); }; updataQuiz(); //정답 확인 const answerQuiz = (index) => { const quizChoices = quizWrap.querySelectorAll(`.quiz__choice input[name="choice-${index}"]:checked`); const quizElement = quizWrap.querySelectorAll(".quiz")[index]; const descElement = quizWrap.querySelectorAll(".quiz__desc")[index]; const answerElement = quizWrap.querySelectorAll(".quiz__answer")[index]; const confirmElement = quizWrap.querySelectorAll(".quiz__confirm")[index]; if (quizChoices. length >0) { const userAnswer = quizChoices[0].value; //사용자가 체크한 정답 if(userAnswer === quizInfo[index].infoAnswer){ quizElement.classList.add("good"); // O표시 }else{ quizElement.classList.add("bad"); // X표시 descElement.classList.remove("none"); // 해설보기 answerElement.classList.remove("none"); // 정답보기 } confirmElement.classList.add("none"); // 정답버튼삭제 }else{ alert("보기를 선택해주세요!"); } }; //페이지가 로드 된 후 실행 document.addEventListener("DOMContentLoaded", () => { updataQuiz(); const quizConfirm = document.querySelectorAll(".quiz__confirm"); quizConfirm.forEach((button, index) => { button.addEventListener("click", () =>{ answerQuiz(index); }); }); });
/* 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