End.js 1.41 KB
Newer Older
baesangjune's avatar
0805    
baesangjune committed
1
import React from 'react'
baesangjune's avatar
baesangjune committed
2
// import tr from './img_end.jpg';
baesangjune's avatar
.    
baesangjune committed
3

Jiwon Yoon's avatar
Jiwon Yoon committed
4

baesangjune's avatar
.    
baesangjune committed
5
// import { Link } from 'react-router-dom';
Jiwon Yoon's avatar
Jiwon Yoon committed
6
7

function End() {
baesangjune's avatar
baesangjune committed
8
9
10
11
    let scores = []
    let score = 0
    const answers = JSON.parse(localStorage.getItem('Answers'))
    const solutions = JSON.parse(localStorage.getItem('Solutions'))
baesangjune's avatar
end    
baesangjune committed
12
    for (let i = 0; i < answers.length; i++) {
baesangjune's avatar
.    
baesangjune committed
13

baesangjune's avatar
baesangjune committed
14
        if (answers[i] === solutions[i]) {
baesangjune's avatar
0    
baesangjune committed
15

baesangjune's avatar
baesangjune committed
16
            scores[i] = 1
baesangjune's avatar
.    
baesangjune committed
17
18
19

        }
        else {
baesangjune's avatar
0805    
baesangjune committed
20

baesangjune's avatar
baesangjune committed
21
            scores[i] = 0
baesangjune's avatar
.    
baesangjune committed
22
        }
baesangjune's avatar
baesangjune committed
23
        score += scores[i]
baesangjune's avatar
.    
baesangjune committed
24
25
    }

Jiwon Yoon's avatar
Jiwon Yoon committed
26
    return (
baesangjune's avatar
.    
baesangjune committed
27
        <>
baesangjune's avatar
end    
baesangjune committed
28
29
30
31
32
33
34
35
36
37
            <div className="container">
                <h2>채점표</h2>
                <table className="table table-bordered" >
                    <thead>
                        <tr>
                            <th>응시자</th>
                            <th>{localStorage.getItem('name')}</th>
                        </tr>
                    </thead>
                    <tbody>
baesangjune's avatar
baesangjune committed
38
                        {scores.map((score, index) => {
baesangjune's avatar
baesangjune committed
39

baesangjune's avatar
end    
baesangjune committed
40
                            return (score === 1) ? <tr><td>Quiz {index + 1}</td> <td> O </td></tr> : <tr><td>Quiz {index + 1}</td> <td> X</td></tr>
baesangjune's avatar
baesangjune committed
41
                        })}
baesangjune's avatar
end    
baesangjune committed
42
43
44
45
46
47
                        <tr>
                            <td>총점</td>
                            <td>{score}</td>
                        </tr>
                    </tbody>
                </table>
baesangjune's avatar
.    
baesangjune committed
48
            </div>
baesangjune's avatar
end    
baesangjune committed
49
50
51
52


            

baesangjune's avatar
.    
baesangjune committed
53
54
        </>

Jiwon Yoon's avatar
Jiwon Yoon committed
55
56
57
    )
}

baesangjune's avatar
.    
baesangjune committed
58
export default End;