* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'DungGeunMo';
}
*::after, *::before {
box-sizing: border-box;
}
a{
text-decoration: none;
}
body {
background-color: #f6f6f6;
background-image:
linear-gradient(90deg, #cdcccc 0px, #cdcccc 1px, transparent 1px, transparent 99px, transparent 100px),
linear-gradient(#cdcccc 0px, #cdcccc 1px, transparent 1px, transparent 99px, transparent 100px),
linear-gradient(#e0e0e0 0px, #e0e0e0 1px, transparent 1px, transparent 99px, transparent 100px),
linear-gradient(90deg, #e0e0e0 0px, #e0e0e0 1px, transparent 1px, transparent 99px, transparent 100px),
linear-gradient(transparent 0px, transparent 5px, #f6f6f6 5px, #f6f6f6 95px, transparent 95px, transparent 100px),
linear-gradient(90deg, #e0e0e0 0px, #e0e0e0 1px, transparent 1px, transparent 99px, #e0e0e0 99px, #e0e0e0 100px),
linear-gradient(90deg, transparent 0px, transparent 5px, #f6f6f6 5px, #f6f6f6 95px, transparent 95px, transparent 100px),
linear-gradient(transparent 0px, transparent 1px, #f6f6f6 1px, #f6f6f6 99px, transparent 99px, transparent 100px),
linear-gradient(#cdcccc, #cdcccc);
background-size:100px 100%, 100% 100px, 100% 10px, 10px 100%, 100% 100px, 100px 100%, 100px 100%, 100px 100px, 100px 100px;
}
#header {
position: absolute;
left: 0;
top: 0;
width: 100%;
background: #262626;
color: #fff;
display: flex;
padding: 10px;
justify-content: space-between;
align-items: center;
z-index: 10;
}
#header::before {
content: '';
border: 4px ridge #a3a3a3;
position: absolute;
left: 5px;
top: 5px;
width: calc(100% - 10px);
height: calc(100% - 10px);
z-index: -1;
}
#header h1 {
padding: 3px 0 6px 10px;
}
#header h1 a {
text-decoration: none;
color: #fff;
}
#header nav {
padding-right: 10px;
}
#header nav li {
list-style: none;
display: inline;
}
#header nav li a {
color: #fff;
display: inline-block;
padding: 0 10px;
transition: all 0.2s;
border: 1px dashed #fff;
}
#header nav li.active a {
background: #fff;
color: #262626;
}
#header nav li a:hover {
opacity: 0.5;
}
#footer {
margin-top: 100px;
width: 100%;
background: #fff;
text-align: center;
padding: 20px;
}
#footer a {
color: #262626;
font-size: 16px;
}
/*quiz__wrap*/
.quiz__wrap {
display: flex;
align-items: center;
justify-content: center;
margin-top: 150px;
flex-wrap: wrap;
height: 100vh;
}
.quiz {
max-width: 500px;
width: 100%;
background: #fff;
border: 8px ridge #cacaca;
margin: 10px;
}
.quiz__type {
background: #cacaca;
text-align: center;
font-size: 14px;
color: #3b3b3b;
border: 3px ridge #cacaca;
padding: 3px 0;
position: relative;
}
.quiz__type::before {
content: '';
position: absolute;
left: 2px;
top: 2px;
width: 5px;
height: 5px;
border: 6px ridge #648a30;
}
.quiz__type::after {
content: '';
position: absolute;
right: 2px;
top: 2px;
width: 5px;
height: 5px;
border: 6px ridge #648a30;
}
.quiz__question {
border-bottom: 6px ridge #cacaca;
border-top: 6px ridge #cacaca;
padding: 13px 30px;
font-size: 24px;
line-height: 1.6;
}
.quiz__number {
font-family: 'Cafe24Dangdanghae';
color: #648a30;
}
.quiz__ask {
font-family: 'Cafe24Dangdanghae';
color: #262626;
}
.quiz__view {
background: #f5f5f5;
position: relative;
}
.quiz__view .true {
position: absolute;
left: 70%;
top: 100px;
width: 120px;
height: 120px;
color: #fff;
border-radius: 50%;
z-index: 100;
line-height: 120px;
text-align: center;
background: #f5534f;
opacity: 0;
}
.quiz__view .false {
position: absolute;
right: 70%;
top: 100px;
width: 120px;
height: 120px;
background: #fff;
border-radius: 50%;
z-index: 100;
line-height: 120px;
text-align: center;
color: #f5534f;
opacity: 0;
}
.quiz__view.dislike .false {
opacity: 1;
animation: wobble 0.6s;
}
.quiz__view.like .true {
opacity: 1;
animation: wobble 0.6s;
}
@keyframes wobble {
0% {
transform: translateZ(0)
}
15% {
transform: translate3d(-25%, 0, 0) rotate(-5deg)
}
30% {
transform: translate3d(20%, 0, 0) rotate(3deg)
}
45% {
transform: translate3d(-15%, 0, 0) rotate(-3deg)
}
60% {
transform: translate3d(10%, 0, 0) rotate(2deg)
}
75% {
transform: translate3d(-5%, 0, 0) rotate(-1deg)
}
100% {
transform: translateZ(0)
}
}
.quiz__answer {
border-top: 6px ridge #cacaca;
background: #f5f5f5;
padding: 10px;
}
.quiz__confirm {
padding: 10px;
border: 6px ridge #cacaca;
width: 100%;
font-size: 22px;
padding: 13px 20px;
background: #d6d6d6;
font-family: 'Cafe24Dangdanghae';
text-shadow: 1px 1px 1px #fff;
transition: all 0.3s;
}
.quiz__confirm:hover {
background: #b3b3b3;
}
.quiz__result {
text-align: center;
padding: 10px;
border: 6px ridge #cacaca;
width: 100%;
font-size: 22px;
padding: 13px 20px;
background: #fff;
font-family: 'Cafe24Dangdanghae';
text-shadow: 1px 1px 1px #fff;
line-height: 1.4;
color: #262626;
}
.quiz__input {
width: 100%;
padding: 13px 20px;
border: 6px ridge #cacaca;
font-size: 22px;
padding: 13px 20px;
background: #fff;
font-family: 'Cafe24Dangdanghae';
text-shadow: 1px 1px 1px #fff;
margin-bottom: 10px;
}
.quiz__selects {
color: #262626;
margin-bottom: 15px;
margin-top: 20px;
}
.quiz__selects label {
display: flex;
}
.quiz__selects label input {
position: absolute;
left: -9999px;
}
.quiz__selects label span {
font-size: 20px;
line-height: 1.3;
padding: 10px 30px 10px 20px;
border-radius: 5px;
margin: 3px 0;
font-family: 'Cafe24Dangdanghae';
display: flex;
align-items: center;
cursor: pointer;
transition: all 0.25s;
}
.quiz__selects label span::before {
content: '';
width: 30px;
height: 30px;
border-radius: 50%;
margin-right: 15px;
background: #fff;
display: flex;
flex-shrink: 0;
box-shadow: inset 0 0 0 4px #64a30b;
transition: all 0.25s;
}
.quiz__selects label input:checked + span {
background-color: #e3fbc0;
}
.quiz__selects label input:checked + span::before {
box-shadow: inset 0 0 0 10px #64a30b;
}
const quizType = document.querySelector(".quiz__type"); //문제유형
const quizNumber = document.querySelector(".quiz__number"); //문제 번호
const quizAsk = document.querySelector(".quiz__ask"); //문제 질문
const quizConfirm = document.querySelector(".quiz__confirm"); //문제 정답버튼
const quizResult = document.querySelector(".quiz__result"); //문제 정답
const quizView = document.querySelector(".quiz__view"); //문제 화면
const quizSelects = document.querySelector(".quiz__selects"); //객관식 보기
const quizChoice = document.querySelectorAll(".choice"); //객관식 보기
const quizSelect = document.querySelectorAll(".select"); //선택하는 보기 input
//문제 정보
const quizInfo = [
{
answerType : "javascript",
answerNum : 1,
answerAsk : "객체 기반의 스크립트 프로그래밍 언어는 무엇입니까?",
answerChoice : ["javascript", "html", "css", "jqeury"],
answerResult : "1",
answerEx : "객체 기반의 스크립트 프로그래밍 언어는 자바스크립트입니다."
}
];
//문제 출력
function updataQuiz(){
//타입, 문제, 정답, 보기
quizType.textContent = quizInfo[0].answerType;
quizNumber.textContent = quizInfo[0].answerNum + ".";
quizAsk.textContent = quizInfo[0].answerAsk;
quizResult.textContent = quizInfo[0].answerEx;
quizChoice.forEach((el,index)=>{ //choice 보기를 다중선택자로 사용해서 출력시키기
el.textContent = quizInfo[0].answerChoice[index];
})
//설명 감추기
quizResult.style.display = "none";
}
updataQuiz();
//정답 확인
function answerQuiz(){
//사용자가 클릭한 input --> checked : 사용자가 선택한 정답 == 객체 안에 정답
for(let i =0; i<quizSelect.length; i++){
if(quizSelect[i].checked == true){ //사용자가 체크한 보기가 true 일 때의 조건문
if(quizSelect[i].value == quizInfo[0].answerResult){ //체크한 보기의 값과 정답이 일치했을 때. 정답/오답
//정답
quizView.classList.remove("dislike");
quizView.classList.add("like"); // 정답일 때 like 클래스 추가
quizConfirm.style.display = "none"; // 정답일 때 정답 확인 버튼 안보이게
quizResult.style.display = "block"; //정답일 때 설명 칸 보이게
} else {
//오답
quizView.classList.remove("like");
quizView.classList.add("dislike"); //오답일 때 dislike 클래스 추가
quizConfirm.style.display = "none";
quizResult.style.display = "block";
}
}
}
}
quizConfirm.addEventListener("click",answerQuiz); //클릭하는 함수 실행.