3 const SelectPrompt = require('./select');
5 class Quiz extends SelectPrompt {
8 if (typeof this.options.correctChoice !== 'number' || this.options.correctChoice < 0) {
9 throw new Error('Please specify the index of the correct answer from the list of choices');
13 async toChoices(value, parent) {
14 let choices = await super.toChoices(value, parent);
15 if (choices.length < 2) {
16 throw new Error('Please give at least two choices to the user');
18 if (this.options.correctChoice > choices.length) {
19 throw new Error('Please specify the index of the correct answer from the list of choices');
25 return state.index === this.options.correctChoice;
28 async result(selected) {
30 selectedAnswer: selected,
31 correctAnswer: this.options.choices[this.options.correctChoice].value,
32 correct: await this.check(this.state)
37 module.exports = Quiz;