Added shuffling for array.

This commit is contained in:
wildscotsmen 2018-10-18 13:51:32 -04:00
parent deb5cc8a01
commit bd270a0e13
2 changed files with 14 additions and 3 deletions

View File

@ -2,10 +2,21 @@ import React, { Fragment } from 'react';
import Grid from '@material-ui/core/Grid'; import Grid from '@material-ui/core/Grid';
import Quiz from 'react-quiz-component'; 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 { class QuizGame extends React.Component {
quiz = { quiz = {
"quizTitle": "Trail Cam Quiz", "quizTitle": "Trail Cam Quiz",
"questions": [ "questions": shuffleArray([
{ {
"question": <Fragment>What animal is this?<br /><img src="/quizimages/question1.jpg" alt=""></img></Fragment>, "question": <Fragment>What animal is this?<br /><img src="/quizimages/question1.jpg" alt=""></img></Fragment>,
"questionType": "text", "questionType": "text",
@ -56,7 +67,7 @@ class QuizGame extends React.Component {
], ],
"correctAnswer": "2" "correctAnswer": "2"
}, },
] ])
}; };
render() { render() {

View File

@ -7,7 +7,7 @@ class QuizPage extends Component {
render() { render() {
return ( return (
<Typography variant='display1' align='center' gutterBottom> <Typography variant='display1' align='center' gutterBottom>
<QuizGame /> <QuizGame />
</Typography> </Typography>
); );
} }