End.js 1.98 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
    let result = ''
baesangjune's avatar
baesangjune committed
9
10
11
12
    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
13
    for (let i = 0; i < answers.length; i++) {
baesangjune's avatar
.    
baesangjune committed
14

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

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

        }
baesangjune's avatar
.    
baesangjune committed
20
21
22
        else if (answers[i] === 0) {
            scores[i] = -1
        }
baesangjune's avatar
.    
baesangjune committed
23
        else {
baesangjune's avatar
0805    
baesangjune committed
24

baesangjune's avatar
baesangjune committed
25
            scores[i] = 0
baesangjune's avatar
.    
baesangjune committed
26
        }
baesangjune's avatar
baesangjune committed
27
        score += scores[i]
baesangjune's avatar
.    
baesangjune committed
28
29
30
        if (score <0){
            score =0
        }
baesangjune's avatar
.    
baesangjune committed
31
32
    }

Jiwon Yoon's avatar
Jiwon Yoon committed
33
    return (
baesangjune's avatar
.    
baesangjune committed
34
        <>
baesangjune's avatar
end    
baesangjune committed
35
36
37
38
39
40
41
42
43
44
            <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
45
                        {scores.map((score, index) => {
baesangjune's avatar
.    
baesangjune committed
46
47
48
49
50
51
52
53
54
55
                            
                            if (score === -1) {
                                result = <tr><td>Quiz {index + 1}</td> <td> 정답이 입력되지 않았습니다. </td></tr>
                            }
                            else if (score === 1) {
                                result = <tr><td>Quiz {index + 1}</td> <td> O </td></tr>
                            }
                            else {
                                result = <tr><td>Quiz {index + 1}</td> <td> X</td></tr>
                            }
baesangjune's avatar
baesangjune committed
56

baesangjune's avatar
.    
baesangjune committed
57
                            return result
baesangjune's avatar
baesangjune committed
58
                        })}
baesangjune's avatar
end    
baesangjune committed
59
60
61
62
63
64
                        <tr>
                            <td>총점</td>
                            <td>{score}</td>
                        </tr>
                    </tbody>
                </table>
baesangjune's avatar
.    
baesangjune committed
65
            </div>
baesangjune's avatar
end    
baesangjune committed
66
67


baesangjune's avatar
.    
baesangjune committed
68

baesangjune's avatar
end    
baesangjune committed
69

baesangjune's avatar
.    
baesangjune committed
70
71
        </>

Jiwon Yoon's avatar
Jiwon Yoon committed
72
73
74
    )
}

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