Last active
November 14, 2020 10:04
-
-
Save webpapaya/ede807d5b921f75290ce4ce82397fcbf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let questions = null; | |
async function getQuestion() { | |
questions = await getQuestions() | |
return questions[Math.random() * questions.length - 1] | |
} | |
function answerQuestion(question, answer) { | |
questions.find((currentQuestion) => currentQuestion.question === question.question) | |
// ^^^^^^^ | |
// if answer question is called before getQuestion is called you'll run into | |
// a null pointer exception (Cannot call find of null) | |
} | |
answerQuestion({ question: "some question", a: '...' }, 'a') | |
// answer question will be called before getQuestion for whatever reason | |
// an exception will be thrown as questions is null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment