Listing 11.12 - Hiding the questions and answers
JS Bin
var getQuiz = function () {
var qIndex = 0;
var questions = [
{
question: "What is the highest mountain in the world?",
answer: "Everest"
},
{
question: "What is the highest mountain in Scotland?",
answer: "Ben Nevis"
},
{
question: "How many munros are in Scotland?",
answer: "284"
}
];
return {
quizMe : function () {
return questions[qIndex].question;
},
showMe : function () {
return questions[qIndex].answer;
},
next : function () {
qIndex = qIndex + 1;
return "Ok";
}
};
};
var quiz = getQuiz();
Listing 11.12 - Hiding the questions and answers - Task 3
- Add a new method to the returned object, showIndex, that returns the value of qIndex.
var getQuiz = function () {
var qIndex = 0;
var questions = [
{
question: "What is the highest mountain in the world?",
answer: "Everest"
},
{
question: "What is the highest mountain in Scotland?",
answer: "Ben Nevis"
},
{
question: "How many munros are in Scotland?",
answer: "284"
}
];
return {
quizMe : function () {
return questions[qIndex].question;
},
showMe : function () {
return questions[qIndex].answer;
},
next : function () {
qIndex = qIndex + 1;
return "Ok";
},
showIndex : function () {
return qIndex;
}
};
};
var quiz = getQuiz();