From bd270a0e134b887c1474b97c4e66192e69b4815d Mon Sep 17 00:00:00 2001 From: wildscotsmen Date: Thu, 18 Oct 2018 13:51:32 -0400 Subject: [PATCH] Added shuffling for array. --- src/components/QuizGame.js | 15 +++++++++++++-- src/pages/QuizPage.js | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/QuizGame.js b/src/components/QuizGame.js index 1705708..e0aae96 100644 --- a/src/components/QuizGame.js +++ b/src/components/QuizGame.js @@ -2,10 +2,21 @@ import React, { Fragment } from 'react'; import Grid from '@material-ui/core/Grid'; import Quiz from 'react-quiz-component'; +function shuffleArray(array) { + var j, x, i; + for (i = array.length - 1; i > 0; i--) { + j = Math.floor(Math.random() * (i + 1)); + x = array[i]; + array[i] = array[j]; + array[j] = x; + } + return array; +} + class QuizGame extends React.Component { quiz = { "quizTitle": "Trail Cam Quiz", - "questions": [ + "questions": shuffleArray([ { "question": What animal is this?
, "questionType": "text", @@ -56,7 +67,7 @@ class QuizGame extends React.Component { ], "correctAnswer": "2" }, - ] + ]) }; render() { diff --git a/src/pages/QuizPage.js b/src/pages/QuizPage.js index ef6cb3f..97f7904 100644 --- a/src/pages/QuizPage.js +++ b/src/pages/QuizPage.js @@ -7,7 +7,7 @@ class QuizPage extends Component { render() { return ( - + ); }