import React, { useState } from 'react' import { Link } from 'react-router-dom'; import Timer from 'react-compound-timer'; // 타이머쓰기위해 import import logo from './img/img_question.png' import fight from './img/img_quiz.png' const QnA = [ { Q: "6 X 4 = ?", Choose: [6, 12, 18, 24], A: "4", N: 1 }, { Q: "3 + 3 = ?", Choose: [2, 4, 6, 8], A: "3", N: 2 }, { Q: "3 - 1 = ?", Choose: [1, 2, 3, 4], A: "2", N: 3 } ] let Answers = [] let Solutions = [4, 3, 2] localStorage.setItem('Solutions', JSON.stringify(Solutions)) function Quiz() { let [question, setQuestion] = useState({ ...QnA[0], i: 0, page: 0, }) let [selected, setSelected] = useState("") //선택한 답을 보여줄 것들 function handleQuestion() { setQuestion({ ...QnA[question.i + 1], i: question.i + 1, page: question.page + 1 }) } let handleChange = (ev) => { ev.preventDefault() //새로고침 안되도록 setSelected(ev.target.value) //selected값 변경 Answers[question.N - 1] = Number(ev.target.id)+1 localStorage.setItem('Answers', JSON.stringify(Answers)) } return ( <>
Answer : {selected} {/* 선택한 값 보여줌 */} {(question.page === QnA.length - 1) ? 제출 : }