@emsee71 wrote:
Hi, I'm having a problem with my code, can you please help me, I'm making a quiz application , my problem is everytime I proceed into the next question it keeps repeating the same question , I used "fisher-yates-shuffle to randomized the questions in my app.I want that all the questions I've pass through will no longer repeat.Can you please help me thanks.
Heres my code:
.factory('wordFactory', function() { var questions = [ { question: "It cannot be changed while program is running.", wordClue: "STATNCO", answer: "constant" }, { question: "Might change while program is running.", wordClue: "EBVAIRAL", answer: "variable" }, { question: "Assignment made when declaring variable", wordClue: "TZNEIIIIAL", answer: "initialize" }, { question: "Controls data values used to set variable.Also called accessor.", wordClue: "TSE THMEOD", answer: "set method" }, { question: "Numeric variable concatenated to String using plus sign.", wordClue: "ACNATEONTEC", answer: "concatenate" } ]; //This is the fisher-yates-shuffle algorithm var shuffleArray = function(array) { var m = array.length, t, i; // While there remain elements to shuffle while (m) { // Pick a remaining element… i = Math.floor(Math.random() * m--); // And swap it with the current element. t = array[m]; array[m] = array[i]; array[i] = t; } return array; } return { getQuestion: function(id) { if(id < questions.length ) { return shuffleArray(questions)[id]; //I've insert the shuffleArray(questions) here } else { return false; } } };
Posts: 1
Participants: 1