Get Programming with JavaScript - Listing 11.12

Listing 11.12 - Hiding the questions and answers

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();

Further Adventures

Listing 11.12 - Hiding the questions and answers - Task 3

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();