Closed codefriar closed 4 years ago
What is missing from the application? Please describe. A way to easily generate a 10 question quiz from a stockpile of questions.
Describe the solution you'd like A button? some ui control that would generate a random 10 question quiz
Describe alternatives you've considered I've been using this Anonymous Apex snippet, which could form the basis for this feature:
List<Quiz_Question__C> questions = [SELECT Id FROM Quiz_question__c]; List<Quiz_Session_question__c> sessionQuestions = [SELECT Id, question__r.name, Question_Index__c FROM Quiz_Session_Question__c]; Set<Quiz_Question__c> chosenQuestions = new Set<Quiz_Question__c>(); for(Quiz_Session_Question__c question: sessionQuestions) { question.question__c = getRandomIdNotAlreadyChosen(); } update sessionQuestions; public id getRandomIdNotAlreadyChosen(){ Integer i = Integer.valueOf((Math.random() * questions.size())); if(!chosenQuestions.contains(questions.get(i))){ chosenQuestions.add(questions.get(i)); return questions.get(i).id; } else { return getRandomIdNotAlreadyChosen(); } }
NB: This is a rough and tumble, but functional implementation.
Additional context
Additionally, this script enforces uniqueness of the questions preventing #55 from coming into play
ps, i'm likely to PR this, once I find the time.
Addressed by #57
What is missing from the application? Please describe. A way to easily generate a 10 question quiz from a stockpile of questions.
Describe the solution you'd like A button? some ui control that would generate a random 10 question quiz
Describe alternatives you've considered I've been using this Anonymous Apex snippet, which could form the basis for this feature:
NB: This is a rough and tumble, but functional implementation.
Additional context