Skip to content

Commit 2c5af03

Browse files
committed
Randomize Correct Answer
1 parent 2aee811 commit 2c5af03

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/App.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ function App() {
2424
}
2525

2626
const { correct_answer, incorrect_answers, question } = questions[index];
27-
const answers = [...incorrect_answers, correct_answer];
27+
// const answers = [...incorrect_answers, correct_answer];
28+
let answers = [...incorrect_answers];
29+
const tempIndex = Math.floor(Math.random() * 4);
30+
if (tempIndex === 3) {
31+
answers.push(correct_answer);
32+
} else {
33+
answers.push(answers[tempIndex]);
34+
answers[tempIndex] = correct_answer;
35+
}
2836

2937
return (
3038
<main>

0 commit comments

Comments
 (0)