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

.

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