$(document).ready(function() { var i,j,flag; var clickedObject; //store the clicked image id var correctCounter = 0; var totalCounter = 0; var objrand = []; var randQues = []; var currentObj; //store the current object clicked var currentQuestion; var NUM_OBJECTS = 4; //no of options var flag_correct; var TOTAL_QUES = 8; var questionsPart1 = new Array( 'Where is the house', 'Where is the tree', 'Where is the mat', 'Where is the mountain', 'Where is the sky', 'Where are the flowers', 'Where is the table', 'Where is the gate' ); var answersPart1 = new Array( "the mountain", "of the house", "the varanda", "the house", "the mountain", "the garden", "the tree", "the tap" ); //current answer among four stored at first 4 options for each questions var answers = new Array('near','behind','inside','outside', 'infront','in','under','above', 'on','behind','near','beside', 'behind','infront','on','under', 'above','below','on','under', 'in','behind','below','beside', 'under','on','above','in', 'beside','infront','below','under' ); var optionImg = new Array('a','b','c','d'); var randNumber = function(limit){ //generate random number between any two ranges var rand_no = Math.floor(limit*Math.random()); return rand_no; }; var generate_random_questions = function(){ randQues[0] = randNumber(TOTAL_QUES); for(i=1; iGame Over !!!'); $('#optionSection').append('
You got '+correctCounter+ ' correct out of '+totalCounter+' questions .
'); } }; var store_clicked_object = function(objectClicked){ var checked; if(objrand[objectClicked] === 0){ if(flag_correct == 1){ //correct at first attempt checked = "correct"; correctCounter++; } } else{ flag_correct = 0; checked = "wrong"; } flag_correct = 0; $('#checkans'+objectClicked).html(''); $('#checkans'+objectClicked).append(''); $('#answer').html(''); if(currentQuestion!=5){ $('#answer').append("It's "); } else{ $('#answer').append("They are "); } $('#answer').append(answers[currentQuestion*4]).append(' '); $('#answer').append(answersPart1[currentQuestion]).append('.'); $('#linkNext').show(); totalCounter++; display_score(); check_game_over(); }; var assignOptions = function (square){ var a = currentQuestion*4; var randOption = objrand[square]+a; $('#optionSection').append('
'); $('#optionSection').append(''); $('#optionSection a:last-of-type').append('
'+ '
'); $('#optionSection a:last-of-type').append('
'+answers[randOption]+'
'); $('#optionSection a:last-of-type').click(function(){ if(flag_correct === 1){ store_clicked_object(square); } }); }; var next_sentence = function(){ flag_correct = 1; generate_random_options_no(); currentQuestion = randQues[totalCounter]; $('#answer').html(''); $('#question').html(''); $('#question').append((totalCounter+1)+'. ').append(questionsPart1[currentQuestion]).append('?'); if(totalCounter!=5){ $('#answer').append("It's").append(' ........... '); } else{ $('#answer').append("They are").append(' ........... '); } $('#answer').append(answersPart1[currentQuestion]).append('.'); for(var i = 0; i < NUM_OBJECTS; i++){ assignOptions(i); } }; function game(){ correctCounter = 0; totalCounter = 0; $('#linkNext').hide(); $('#optionSection').html(''); display_score(); generate_random_questions(); next_sentence(); } $('#linkNext').click(function(){ $('#linkNext').hide(); $('#optionSection').html(''); next_sentence(); }); $('#linkStart').click(function(){ game(); }); $('#linkPlayAgain').click(function(){ game(); }); display_score(); $('#linkNext').hide(); });//end of DOM