Commit 68deb13a authored by baesangjune's avatar baesangjune
Browse files

.

parent 6bdefa5b
......@@ -8,12 +8,12 @@ function End() {
for (let i = 0; i < 3; i++) {
if (localStorage.getItem(i + '번문제답') === localStorage.getItem(i + '번문제정답')) {
alert('정답입니다.')
k[i] = ['O', 1]
}
else {
alert('오답입니다.')
k[i] = ['X', 0]
}
}
......
import React from 'react'
import { Link } from 'react-router-dom';
import React, { useState } from 'react'
import { Redirect } from 'react-router-dom';
// import { Link } from 'react-router-dom';
function Home() {
const [name, setName] = useState('')
const [done, setDone] = useState(false)
const handleChange = (event) => {
setName(event.target.value)
}
function checking(event) {
if (!name) {
alert('이름을 입력하세요')
}
else {
alert('입력하신 이름은' + name + '입니다.')
localStorage.setItem('name', name)
setDone(true)
}
}
return (
<>
<div classXName="Box">
<div className="Name">
이름을 입력하세요
<input onChange={(event) => localStorage.setItem('name', event.target.value)} />
{done ? <Redirect to='/quiz' /> : ''}
<div className="Box">
<div className="Name"> 이름을 입력하세요
<input onChange={handleChange} />
</div>
{/* sessionStorage를 사용해야는지 localstorage를 사용해야하는지 */}
</div>
<div className='Box2'>
<Link to="/quiz">
<div>
<button className="QuizStart" onClick={checking}>Quiz Start !</button>
</Link>
</div>
</div>
</>
)
}
function checking(event) {
if (localStorage.getItem('name') === null || localStorage.getItem('name').length === 0) {
alert('이름을 입력하세요')
}
else {
alert('입력하신 이름은 '+localStorage.getItem('name')+'입니다.')
}
}
export default Home;
\ No newline at end of file
......@@ -37,8 +37,8 @@ class Quiz extends React.Component {
if (answers[i].checked) {
// checked_index = i;
checked_value = answers[i].value;
localStorage.setItem(this.state.i+'번문제답', checked_value)
localStorage.setItem(this.state.i+'번문제정답', question[i-1].A)
localStorage.setItem(this.state.i+1+'번문제답', checked_value)
localStorage.setItem(this.state.i+1+'번문제정답', question[i-1].A)
}
}
}
......@@ -94,7 +94,7 @@ class Quiz extends React.Component {
}
{/* <input onKeyPress="this.enterkey()"/> */}
{this.timer()}
{/* {this.timer()} */}
</div>
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment