Quiz

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
소스 보기
JAVASCRIPT
CSS
// 선택자 
    const quizWrap = document.querySelector(".quiz__wrap"); 
    const quizHeader = quizWrap.querySelector(".quiz__header");
    const quizQuestion = quizWrap.querySelector(".quiz__question");
    const quizAnswer = quizWrap.querySelector(".quiz__answer");
    const quizDesc = quizWrap.querySelector(".quiz__desc");
    const quizChoice = quizWrap.querySelectorAll(".quiz__choice span");
    const quizSelect = quizWrap.querySelectorAll(".quiz__choice input");
    const quizConfirm = quizWrap.querySelector(".quiz__confirm");

    // 문제 정보
    const quizInfo = [
        {
            infoDate : "2016년 4회",
            infoType : "웹디자인 기능사",
            infoNum : "01",
            infoQuestion : "다음 중 디자인의 기본 요소들로 옳은 것은?",
            infoChoice : ["선, 색채, 공간, 수량", "점, 선, 면, 질감", "시간, 수량, 구조, 공간", "면, 구조, 공간, 수량"],
            infoAnswer : "2",
            infoDesc : "디자인의 기본 요소에는 점, 선, 면, 질감이 있습니다."
        }
    ];

    // 문제 출력
    quizHeader.innerHTML = quizInfo[0].infoDate + " " + quizInfo[0].infoType;
    quizQuestion.innerHTML = quizInfo[0].infoNum + ". " + quizInfo[0].infoQuestion;
    quizAnswer.innerText = quizInfo[0].infoAnswer;
    quizDesc.innerText = quizInfo[0].infoDesc;

    for(let i=0; i<quizChoice.length; i++){
        quizChoice[i].innerText = quizInfo[0].infoChoice[i];
    }

    // 정답 확인
    quizConfirm.addEventListener("click", () => {
        let seletedChoice = null;

        for(let i=0; i<quizSelect.length; i++){
            if(quizSelect[i].checked){
                seletedChoice = quizSelect[i].value;
                break;
            }
        }

        if(seletedChoice !== null){
            if(seletedChoice == quizInfo[0].infoAnswer){
                alert("정답입니다.");
                quizDesc.classList.remove("none");
            } else {
                alert("오답입니다.");
                quizAnswer.classList.remove("none");
                quizDesc.classList.remove("none");
            }
        } else {
            alert("보기를 선택해주세요!! 😄");
        }
    });
 
/* 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