Skip to content

Commit 05a0559

Browse files
committed
created a seperate function to generate ramdom question Id.
1 parent e2abe6a commit 05a0559

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/components/Table/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,21 +207,20 @@ const Table = () => {
207207
},
208208
{
209209
Header: () => {
210+
const randomQuestion = () => {
211+
const random = Math.floor(Math.random() * questions.length);
212+
const questionId = questions[random].id;
213+
const questionSlug = questions[questionId].url;
214+
window.open(`${questionSlug}`, '_blank');
215+
};
210216
return (
211217
<>
212218
<div
213219
style={{ whiteSpace: 'nowrap', display: 'inline-block' }}
214220
>
215221
Questions{' '}
216222
<Button
217-
onClick={() => {
218-
const random = Math.floor(
219-
Math.random() * questions.length,
220-
);
221-
const questionId = questions[random].id;
222-
const questionSlug = questions[questionId].url;
223-
window.open(`${questionSlug}`, '_blank');
224-
}}
223+
onClick={randomQuestion}
225224
color="dark"
226225
id="random-question-button"
227226
size="sm"

0 commit comments

Comments
 (0)