$(document).ready(function(){ var k = Karma({ audio: [{'name':'correct','file':'correct.wav'}, {'name':'incorrect','file':'incorrect.wav'} ]}); k.ready(function(){ var i,j; var totalCounter; var correctCounter; var currentQuestion; var TOTAL_QUES = 8; var flag_correct; var randPositions = []; var check_num; var infoQues1 = new Array('एउटा बट्टामा y ओटा लडडुहरु छन ', 'एउटा सीसाकलमको बट्टामा p ओटा सीसाकलमहरु छन', 'एउटा बोरामा r केजी चामल छ ', 'एउटा सिसीमा z लिटर तेल छ ', 'एउटा कार्टुनमा x प्याकेट चाउचाउ छन ', 'एउटा डालोमा n ओटा नरिवलहरु छन ', 'एउटा झोलामा m केजी आपहरु छन', 'यो एउटा बिस्कुटको प्याकेटमा x ओटा बिस्कुटहरु छन ' ); var infoQues2 = new Array('यदि एउटा बट्टामा 20 ओटा लडडुहरु छन भने 5 ओटा बट्टामा', 'यदि एउटा बट्टामा 10 ओटा सीसाकलमहरु छन भने 4 ओटा बट्टामा', 'यदि एउटा बोरामा 50 केजी चामल छ भने 4 ओटा बोरामा जम्मा ', 'यदि एउटा सिसीमा 2 लिटर तेल छ भने 4 ओटा सिसीमा जम्मा ', 'यदि एउटा कार्टुनमा 30 प्याकेट चाउचाउ छन भने 3 ओटा कार्टुनमा जम्मा ', 'यदि एउटा डालोमा 25 ओटा नरिवलहरु छन भने 3 ओटा डालोमा जम्मा ', 'यदि एउटा झोलामा 7 केजी आपहरु छन भने 2 ओटा झोलामा जम्मा ', 'यदि एउटा प्याकेटमा 15 बिस्कुट ओटा बिस्कुट छन भने 3 ओटा प्याकेटमा जम्मा ' ); var infoQues3 = new Array('ओटा लडडुहरु छन','सीसाकलमहरु छन','केजी चामल छ','लिटर तेल छ', 'प्याकेट चाउचाउ छन','ओटा नरिवलहरु छन','केजी आपहरु छन','बिस्कुटहरु छन' ); var variableName = new Array('y','p','r','z','x','n','m','x'); var perPack = new Array('20','10','50','2','30','25','7','15'); var quantity = new Array('5','4','4','4','3','3','2','3'); var answers = new Array('100','40','200','8','90','75','14','45'); var scoreboard = $('#score_box').scoreboard({'layout':'horizontal', 'winningScore': TOTAL_QUES}); var genRandPosition=function (){ randPositions[0] = k.rand(0,TOTAL_QUES-1); for(i=1; i'); $('.bgQuesAns').html(''); $('.bgQuestion').addClass('quesText').html(infoQues1[currentQuestion]+' ।'); $('.bgCalculation').addClass('quesText').html(infoQues2[currentQuestion]); $('.bgCalculation').append('
'); $('.bgCalculation').append('
'); for( i = 0; i< quantity[currentQuestion]; i++){ $('#textQues1').append(variableName[currentQuestion]); $('#textQues2').append(''); if(i != quantity[currentQuestion]-1){ $('#textQues1').append('+'); $('#textQues2').append('+'); } else{ $('#textQues1').append(' = ').append(quantity[currentQuestion]+' * '+variableName[currentQuestion]); $('#textQues2').append(' = ').append(quantity[currentQuestion]+' *'+''); } $("input#text1").focus(); } foucs_blur(); } }; function game_start(){ $('#gameOver').hide(); $('#linkCheck').show(); $('#section').removeClass('backOpaque'); genRandPosition(); next_question(); } function game() { totalCounter = 0; correctCounter = 0; $('#section').html('').append('
'); $('#left-side').append('
'); $('#left-side').append('
'); $('#section').append('
'); $('#right-side').append('
'); $('#right-side').append('
'); $('#help').hide(); $('.bgAns').hide(); $('#linkCheck').hide(); $('#gameOver').hide(); } game(); var delay_nextQues = function(){ document.delayForm.delayval.value = 1; next_question(); }; var delay_gameOver = function(){ document.delayForm.delayval.value = 1; $('#section').addClass('backOpaque'); $('#linkCheck').hide(); $('#gameOver').show(); }; var check_answer = function(){ if(check_num === 0){ var textVal = $('#text1').val(); if(textVal === perPack[currentQuestion]){ // first one is correct k.audio.correct.play(); $('.bgCalculation').append('
'); $('.bgCalculation').append('
'); $('#textQues3').append(' =         ').append(''); $('#textQues4').append(infoQues3[currentQuestion]+' ।'); $('#text1').attr("disabled", true); $('.blankBoxes').css({'padding':'0'}).html(perPack[currentQuestion]); check_num++; $("input#text2").focus(); foucs_blur(); } else{ k.audio.incorrect.play(); flag_correct = 0; } } else{ textVal = $('#text2').val(); //if(textVal === perPack[currentQuestion] * quantity[currentQuestion]){ if(textVal === answers[currentQuestion]){ k.audio.correct.play(); if(flag_correct === 1){ scoreboard.scoreboard('inc'); correctCounter++; } scoreboard.scoreboard('incTotal'); totalCounter++; t=setTimeout(function(){delay_nextQues();},1000); } else{ flag_correct = 0; k.audio.incorrect.play(); } } }; function foucs_blur(){ $('input[type="text"]') .focus(function() { $(this).removeClass('incorrect').addClass("focus"); }) .blur(function() { $(this).removeClass("focus"); }) .keypress(function(event) { if(event.which === 13){ check_answer(); } }); $('#linkCheck').click(function(){ check_answer(); }); } $('#linkStart').click(function(){ game_start(); }); $('#linkPlayAgain').click(function(){ scoreboard.scoreboard('reset'); game_start(); }); $('#linkHelp').click(function(){ $('#help').slideDown(2000); }) .mouseout(function(){ $('#help').slideUp(2000); }); }); //end of k.ready }); //end of document.ready