Skip to content

Instantly share code, notes, and snippets.

@webpapaya
Last active November 14, 2020 10:04
Show Gist options
  • Save webpapaya/ede807d5b921f75290ce4ce82397fcbf to your computer and use it in GitHub Desktop.
Save webpapaya/ede807d5b921f75290ce4ce82397fcbf to your computer and use it in GitHub Desktop.
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