var CorrectAnswers = {
"question1": "question1_answer_3",
"question2": "question2_answer_1",
"question3": "question3_answer_2",
};
var correct_page = {
"question1": "correct_page",
"question2": "correct_page_2",
"question3": "correct_page_3",
};
var incorrect_page = {
"question1": "incorrect_page",
"question2": "incorrect_page_2",
"question3": "incorrect_page_3",
};
var screenButtons =
{
"question1" : 4,
"question2" : 4,
"question3" : 4
};
setAnswerButtonEvent();
onEvent("start_button", "click", function( ) {
console.log("Start Button Clicked");
setScreen("question1");
});
function setAnswerButtonEvent(){
var keys = Object.keys(screenButtons);
console.log(keys);
Object.keys(screenButtons).forEach(function (key) {
var buttonCount = screenButtons[key];
for(var i=1; i <= buttonCount; i++) {
var answerButtonName = key + "_answer_" + i;
console.log(answerButtonName);
checkAnswer(key, answerButtonName );
}
});
}
function checkAnswer(question, choice ){
onEvent(choice, "click", function(event) {
console.log(choice + " is clicked!");
if (CorrectAnswers[question] !== choice ) {
setScreen(incorrect_page[question]);
} else {
console.log("correct page");
setScreen(correct_page[question]);
}
});
}
onEvent("correct_continue_button_1", "click", function( ) {
console.log("Correct Continue Button Clicked");
setScreen("question2");
});
onEvent("incorrect_continue_button_1", "click", function( ) {
console.log("Incorrect Continue Button Clicked");
setScreen("question2");
});
onEvent("correct_continue_button_2", "click", function( ) {
console.log("Correct Continue Button Clicked");
setScreen("question3");
});
onEvent("incorrect_continue_button_2", "click", function( ) {
console.log("Incorrect Continue Button Clicked");
setScreen("question3");
});
onEvent("correct_continue_button_3", "click", function( ) {
console.log("Correct Continue Button Clicked");
setScreen("finish_page");
});
onEvent("incorrect_continue_button_3", "click", function( ) {
console.log("Incorrect Continue Button Clicked");
setScreen("finish_page");
});