-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreport.js
More file actions
50 lines (42 loc) · 940 Bytes
/
report.js
File metadata and controls
50 lines (42 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const report = (answers, database) => {
/**
* Response Prototype
* result = {
* score: 50,
* correct: 5,
* wrong: 5,
* inputs: ['opt_a', 'opt_b', 'opt_c']
* }
*/
const user_inputs = [];
let
i = 0,
correct = 0,
wrong = 0,
score;
let len = database.length;
for (; i < len; i++) {
let a = answers[`q${i}`];
let b = database[i]['ans'];
if (!a) {
wrong++;
} else {
user_inputs.push(a);
if (a == b) {
correct++;
}
else {
wrong++;
}
}
}
score = Math.round((correct / i) * 100);
const result = {
score: score,
correct: correct,
wrong: wrong,
inputs: user_inputs
};
return result;
};
module.exports = report;