Commit a7a24e03 authored by JeongYeonwoo's avatar JeongYeonwoo
Browse files

bootHome

parent 8b898374
......@@ -11,20 +11,20 @@ function App() {
<Router>
<header>
<Link to="/">
<button>Calculus</button>
<button className="calcButton">Calculus</button>
</Link>
</header>
<hr/>
<hr />
<div>
<Switch>
<Route exact path="/">
<Home/>
<Home />
</Route>
<Route path="/quiz">
<Quiz/>
<Quiz />
</Route>
<Route path="/end">
<End/>
<End />
</Route>
</Switch>
</div>
......
import React, { createContext } from 'react'
import tr from './img/img_end.jpg';
import React from 'react'
import tr from './img_end.jpg';
import './End.css'
// import { Link } from 'react-router-dom';
function End() {
let a = []
for (let i = 0; i < 3; i++) {
if (localStorage.getItem(''+(i+1)) === localStorage.getItem('정답'+(i+1))) {
let scores = []
let score = 0
const answers = JSON.parse(localStorage.getItem('Answers'))
const solutions = JSON.parse(localStorage.getItem('Solutions'))
for (let i = 0; i < answers.length ; i++) {
a[i] =1
if (answers[i] === solutions[i]) {
localStorage.setItem('채점'+(i+1),'O')
scores[i] = 1
}
else {
a[i] =0
localStorage.setItem('채점'+(i+1),'X')
scores[i] = 0
}
score += scores[i]
}
return (
<>
<div className="card" style={{fontSize:'30px', textAlign:"center"}} >
<div className="card" style={{ fontSize: '30px', textAlign: "center" }} >
<div className='card-header'>
-채점표-
-채점표-
<div className='card-body'>
<h3 className='card-title'>이름 : {localStorage.getItem('name')}</h3>
<h3 className='card-title'>이름 : {localStorage.getItem('name')}</h3>
<p className='card-text'>Quiz 1 : {localStorage.getItem('채점1')}</p>
<p className='card-text'>Quiz 2 : {localStorage.getItem('채점2')}</p>
<p className='card-text'>Quiz 3 : {localStorage.getItem('채점3')}</p>
<p className='card-text'>Total Score : {a[0] + a[1] + a[2]}</p>
</div>
<div style={{marginTop:'100px'}}className="Box text-center">
<img src={tr} alt="수고" />
</div>
{scores.map((score, index) => {
return (score===1) ? <p className='card-text'>Quiz {index+1} : 'O' </p> : <p className='card-text'>Quiz {index+1} : 'X' </p>
// if (score === 1) {
// return <p className='card-text'>Quiz {index+1} : 'O' </p>
// }
// else { return <p className='card-text'>Quiz {index+1} : 'X' </p> }
})}
<p className='card-text'>Total Score : {score}</p>
</div>
<div style={{ marginTop: '100px' }} className="Box text-center">
<img src={tr} alt="수고" />
</div>
</div>
</div>
</>
......
.container {
background-image: url("./img/img_study.jpg");
.container-fluid {
/* background-image: url("./img/img_study.jpg"); */
background-color: white;
background-size: 100%;
width: 100%;
height: 880px;
height: 600px;
background-repeat: no-repeat;
}
/* .writename{
class : text-center
} */
/* .Name {
font-size: 30px;
position: absolute;
......
import bg from './img_study.jpg'
import React, { useState } from 'react'
import { Redirect } from 'react-router-dom';
import './Home.css'
......@@ -25,30 +24,39 @@ function Home() {
return (
<>
{done ? <Redirect to='/quiz' /> : ''}
<div style={{ backgroundImage: 'url(' + bg + ')', backgroundColor: "grey", backgroundSize: "100%", width: "100%", height: "880px", backgroundRepeat: 'no-repeat' }}>
{/* <div className="Main"></div> */}
<div className="container">
<div className="text-center">
이름을 입력하세요
<input className="inputBox" onChange={handleChange} />
<div className='Box2'>
<button className="btn btn-dark" onClick={checking}>Quiz Start !</button>
</div>
<div className="d-flex justify-content-center ">
<table className="table table-borderless" style={{width : "500px"}}>
<thead className="text-center">
<tr style={{height:"180px"}}></tr>
</thead>
<tbody className="text-center">
<tr>
<td>이름 입력<input className="ml-2 inputBox" onChange={handleChange} /></td>
</tr>
<tr>
<td>비밀번호<input className="ml-2 inputBox" onChange={handleChange} /></td>
</tr>
<tr>
<td><button className="mt-4 btn btn-dark" onClick={checking}>Quiz Start !</button></td>
</tr>
</tbody>
</table>
</div>
{/*
<div className="container-fluid">
<div className="text-center">
<div>
이름을 입력하세요
</div>
{/* localStorage를 사용해야는지 localstorage를 사용해야하는지 */}
</div>
<div>계산수학</div>
<input className="inputBox" onChange={handleChange} />
<div className='Box2'>
<button className="btn btn-dark" onClick={checking}>Quiz Start !</button>
</div>
</div>
</div> */}
</div>
<div>계산수학</div>
</>
)
}
export default Home;
......@@ -31,7 +31,7 @@
margin: 30px;
margin-left: 650px;
margin-top: 150px;
margin-bottom: 200px;
margin-bottom: 200px;
width: 220px;
height: 50px;
font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
......
......@@ -10,7 +10,9 @@ const QnA = [
{ 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({
......@@ -28,11 +30,9 @@ function Quiz() {
ev.preventDefault() //새로고침 안되도록
setSelected(ev.target.value) //selected값 변경
let checked_number = ev.target.id;
localStorage.setItem('' + (question.N), Number(checked_number) + 1)
localStorage.setItem('정답' + (question.N), QnA[question.N - 1].A)
Answers[question.N - 1] = Number(ev.target.id)+1
localStorage.setItem('Answers', JSON.stringify(Answers))
}
return (
<>
......@@ -60,20 +60,14 @@ function Quiz() {
</p>
</div>
{/* 마지막 질문일 경우 /end페이지로 이동, 그렇지 않을경우는 this.handleQuestion발생 */}
{/* {(question.page === QnA.length - 1)
? <Link to="/end">제출</Link>
: <button type="button" onClick={handleQuestion} >다음</button>
} */}
{/* <input onKeyPress="this.enterkey()"/> */}
<p style={{ textAlign: "center", fontSize: "30px", color: "crimson" }}>
<Timer
initialTime={3600000}
......@@ -92,14 +86,10 @@ function Quiz() {
)}
</Timer> {/* npm i react-compound-timer */}
</p>
</div>
</>
)
}
export default Quiz;
\ No newline at end of file
export default Quiz;
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
import React from 'react';
import './App.css';
import Home from './Home'
import Quiz from './Quiz'
import End from './End'
import { BrowserRouter as Router, Link, Switch, Route } from 'react-router-dom';
function App() {
return (
<Router>
<header>
<Link to="/">
<button className="calcButton">Calculus</button>
</Link>
</header>
<hr />
<div>
<Switch>
<Route exact path="/">
<Home />
</Route>
<Route path="/quiz">
<Quiz />
</Route>
<Route path="/end">
<End />
</Route>
</Switch>
</div>
</Router>
)
}
export default App;
\ No newline at end of file
import React from 'react';
import { render } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
const { getByText } = render(<App />);
const linkElement = getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
.card {
font-size:30px;
text-align:center;
}
.Box {
margin-top:100px;
}
\ No newline at end of file
import React from 'react'
import './End.css'
import tr from './img/img_end.jpg';
// import { Link } from 'react-router-dom';
function End() {
let a = []
for (let i = 0; i < 3; i++) {
if (localStorage.getItem('' + (i + 1)) === localStorage.getItem('정답' + (i + 1))) {
a[i] = 1
localStorage.setItem('채점' + (i + 1), 'O')
}
else {
a[i] = 0
localStorage.setItem('채점' + (i + 1), 'X')
}
}
return (
<>
<div className="card" >
<div className='card-header'>
-채점표-
<div className='card-body'>
<h3 className='card-title'>이름 : {localStorage.getItem('name')}</h3>
<p className='card-text'>Quiz 1 : {localStorage.getItem('채점1')}</p>
<p className='card-text'>Quiz 2 : {localStorage.getItem('채점2')}</p>
<p className='card-text'>Quiz 3 : {localStorage.getItem('채점3')}</p>
<p className='card-text'>Total Score : {a[0] + a[1] + a[2]}</p>
</div>
<div style={{ marginTop: '100px' }} className="Box text-center">
<img src={tr} alt="수고" />
</div>
</div>
</div>
</>
)
}
export default End;
.container-fluid {
background-image: url("./img/img_study.jpg");
background-color: white;
background-size: 100%;
width: 100%;
height: 600px;
background-repeat: no-repeat;
}
/* .Name {
font-size: 30px;
position: absolute;
top: 330px;
left: 38%
} */
/* .inputBox {
margin-left: 30px;
inline-size: 200px;
block-size: 40px;
font-size: 40px;
} */
/* .QuizStart {
margin-top: 35%;
block-size: 100px;
inline-size: 200px;
font-size: 35px;
} */
\ No newline at end of file
import React, { useState } from 'react'
import { Redirect } from 'react-router-dom';
import './Home.css'
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 (
<>
{done ? <Redirect to='/quiz' /> : ''}
<div className="container-fluid">
<div className="text-center">
<div>
이름을 입력하세요
</div>
<input className="inputBox" onChange={handleChange} />
<div className='Box2'>
<button className="btn btn-dark" onClick={checking}>Quiz Start !</button>
</div>
</div>
{/* localStorage를 사용해야는지 localstorage를 사용해야하는지 */}
</div>
<div>계산수학</div>
</>
)
}
export default Home;
.Main {
background: gray;
background-image: url('');
display: inline-block;
border: 3px solid black;
width: 750px;
height: 180px;
text-align: center;
margin-left: 410px;
margin-top: 10px;
font-size: 120px;
font-family: cursive;
color : greenyellow;
text-shadow :
-3px -3px 0 #000, /* 왼쪽 위 그림자 */
3px -3px 0 #000, /* 오른쪽 위 그림자 */
-3px 3px 0 #000, /* 왼쪽 아래 그림자 */
3px 3px 0 #000; /* 오른쪽 아래 그림자 */
}
/* .Name {} */
.Box {
text-align: center;
margin: 0 auto;
margin-top: 75px;
}
.QuizStart {
margin: 30px;
margin-left: 650px;
margin-top: 150px;
margin-bottom: 200px;
width: 220px;
height: 50px;
font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
font-size: 20px;
letter-spacing: 3px;
}
.card{
text-align: center;
margin: 100px;
font-size: 10px;
}
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 }
]
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값 변경
let checked_number = ev.target.id;
localStorage.setItem(''+(question.N), Number(checked_number)+1)
localStorage.setItem('정답' + (question.N), QnA[question.N-1].A)
}
return (
<>
<div style={{ fontSize: '80px', marginBottom: '100px', textAlign: "center", backgroundColor: 'yellow' }}>미적분학 퀴즈</div>
<img src={fight} style={{ position: "absolute", left: "1050px", top: '200px' }} alt="lion" />
<div className="Quiz" >
<h1><img src={logo} style={{ marginLeft: "450px" }} width='75' height='75' alt='question' /> <span style={{ fontSize: "75px", marginLeft: "30px" }}>{question.Q}</span></h1>
{/* <div style={{ marginTop: "30px", marginBottom: "30px", marginLeft:'450px', fontSize:'40px' }}>정답을 선택하세요</div> */}
<div>
<form>
{question.Choose.map((a, index) =>
<div key={index}>
<input type="radio" name='answer' id={index} value={a} onClick={handleChange} style={{ marginLeft: "475px", width: "25px", height: "25px" }} />
<label htmlFor={a} style={{ fontSize: "40px", marginLeft: "22px" }}>{a}</label>
</div>
)}
<input hidden type="submit" value="확인" /> {/*버튼 숨김*/}
</form>
<p style={{ fontSize: "40px", marginLeft: "480px" }}>Answer :<span style={{ color: "green", fontWeight: "bold", fontSize: "90px", marginLeft: "30px" }}> {selected}</span> {/* 선택한 보여줌 */}<span style={{ marginLeft: "50px" }}> {(question.page === QnA.length - 1)
? <Link to="/end">제출</Link>
: <button type="button" onClick={handleQuestion} style={{ width: "85px", height: "40px" }} >다음</button>
}</span>
</p>
</div>
{/* 마지막 질문일 경우 /end페이지로 이동, 그렇지 않을경우는 this.handleQuestion발생 */}
{/* {(question.page === QnA.length - 1)
? <Link to="/end">제출</Link>
: <button type="button" onClick={handleQuestion} >다음</button>
} */}
{/* <input onKeyPress="this.enterkey()"/> */}
<p style={{ textAlign: "center", fontSize: "30px", color: "crimson" }}>
<Timer
initialTime={3600000}
direction="backward"
checkpoints={[
{
time: 0,
callback: <Link to="/end">제출</Link>
// history.go(1)
}
]}
>
{() => (
<>
<Timer.Minutes /> : <Timer.Seconds></Timer.Seconds> / 60 : 00 </>
)}
</Timer> {/* npm i react-compound-timer */}
</p>
</div>
</>
)
}
export default Quiz;
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