import React from 'react'; // import logo from './logo.svg'; import './Quiz.css'; const question = [ { Q: "6 X 4 ?", Choose: [6, 12, 18, 24], A: "" }, { Q: "3 + 3 ?", Choose: [2, 4, 6, 8], A: "" }, { Q: "3 - 1 ?", Choose: [1, 2, 3, 4], A: "" } ] class Quiz extends React.Component { constructor(props) { super(props) // this.setAnswer = this.setAnswer.bind(this) this.setQuestion = this.setQuestion.bind(this) this.ShowQuiz = this.ShowQuiz.bind(this) this.answerbox = this.answerbox.bind(this) this.state = { ...question[0], i: 0, page: 0, } // this.textInput = React.createRef() } ShowQuiz() { this.setState({ page: 1 }) } setQuestion() { //값이 입력되지 않은채로 넘겨졌을 때 문제 해결 해야 함-sj- this.setState({ ...question[this.state.i + 1], i: this.state.i + 1 }) } //answerbox - answer박스의 값을 네임리스트로 받아와서 값을 localstorage에 저장 answerbox() { let answers = document.getElementsByName('answer'); let count = answers.length // var checked_index = -1; var checked_value = ''; for (var i = 0; i < count; i++) { if (answers[i].checked) { // checked_index = i; checked_value = answers[i].value; localStorage.setItem('answer-'+i, checked_value) } } // alert('선택된 항목 인덱스: ' + checked_index + '\n선택된 항목 값: ' + checked_value); // if (document.getElementsByName("answer")[i].checked === true) { // alert(document.getElementsByName("answer")[i].value); // } } // setAnswer(e) { // question[this.state.i]["A"] = e.target.value // this.setState({ v: e.target.value }) // console.log(this.state) // console.log(question) // } render() { if (this.state.page === 1) { this.answerbox() if (this.state.i === question.length) { return (

수고하셨습니다!

) } else { return (

Q:{this.state.Q}

{this.state.Choose.map((a) =>
)}
정답을 입력하세요
{/*
*/}
) } } else { return (

Calculus

이름을 입력하세요 { console.log(event.target.value) }} />
) } } } export default Quiz;