Last active
April 7, 2021 21:09
-
-
Save robinheinze/0701db7a9d7482e9bd02b1086257a219 to your computer and use it in GitHub Desktop.
Question with guess helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const QuestionModel = types | |
.model("Question") | |
.props({ | |
id: types.identifier, | |
category: types.maybe(types.string), | |
type: types.enumeration(["multiple", "boolean"]), | |
difficulty: types.enumeration(["easy", "medium", "hard"]), | |
question: types.maybe(types.string), | |
correctAnswer: types.maybe(types.string), | |
incorrectAnswers: types.optional(types.array(types.string), []), | |
guess: types.maybe(types.string), | |
}) | |
.views(self => ({ | |
get allAnswers() { | |
return shuffle(self.incorrectAnswers.concat([self.correctAnswer])) | |
}, | |
get isCorrect() { | |
return self.guess === self.correctAnswer | |
}, | |
})) | |
.actions(self => ({ | |
setGuess(guess: string) { | |
self.guess = guess | |
}, | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment