guys!
I am trying to build a basic quiz application using JavaScript and I came across a little "bump"
Why doesn't my code store an element of the allQuestions array in the currentQuestion variable ?
This is the code:
var allQuestions = [
{question: 'What is the first letter of the alphabet?',
choices: ['a', 'b', 'c', 'd'],
correctAnswer: 0
},
{
question: 'What is the second letter of the alphabet?',
choices: ['a', 'b', 'c', 'd'],
correctAnswer: 1
},
{
question: 'What is the third letter of the alphabet?',
choices: ['a', 'b', 'c', 'd'],
correctAnswer: 2
},
{
question: 'What is the last letter of the alphabet?',
choices: ['a', 'b', 'c', 'z'],
correctAnswer: 3
}];
var currentQuestion = {};
function pickRandomQuestion(arr) {
return this[Math.floor(Math.random() * this.length)];
}
currentQuestion = pickRandomQuestion(allQuestions);
Thank you!