const baseUrl = 'http://face3d.4dage.com:8102'; var questionsData =[]; var currData = []; var correctnum = 0; var currnum = 1; function getQuestionsData() { return new Promise (function(resolve,reject){ $.ajax({ url:baseUrl + '/api/web/list', type: 'POST', success: function(res) { resolve(res.data) }, error: function(err) { console.log(err) } }) }) } function updateQuestion() { console.log(currData); var html = `

${currnum}.${currData?currData.title:''}

`; $(".topic").html(html); } $("#gui-modes-backIndex").click(function() { location.reload(); }) $("#gui-modes-quiz").click(function() { $("#game").show(); }) $("#closeGame").click(function() { currnum = 1; correctnum = 0; $(".process").hide(); $(".start").show(); $("#game").hide(); }) $("#start_btn").click(function() { currnum = 1; correctnum = 0; getQuestionsData().then(function(v) { console.log(v) questionsData = v.filter(function(item){return item.type=='1'}) ; currData= questionsData[currnum-1<0?0:currnum-1]; console.log(currData) $("#start_page").hide(); $("#process_page").show(); updateQuestion(); answer(); }) }) $("#next_btn").click(function() { console.log(currnum,correctnum) if(currnum==10&&correctnum<7) { $("#process_page").hide(); $(".again").show(); }else if(currnum==10&&correctnum>=7) { $("#process_page").hide(); $(".success").show(); }else { currnum ++; currData= questionsData[currnum-1] updateQuestion(); answer(); } }) var params = JSON.stringify({ "pageNum": 1, "pageSize": 1, "searchKey": "", "type": 1 }) function answer () { $(".topic").one('click','li',function(item){ flag= true; if($(this).attr("data-correct")==0){ $(this).addClass("wrong"); $("#options li").each(function(i,item) { if($(item).attr("data-correct")==1){ setTimeout(function(){$(item).addClass("correct")},1000) } }) }else { correctnum = correctnum + 1; $(this).addClass("correct"); } if(currnum==10) { if(correctnum>=7) { $("#process_page").hide(); $(".success").show(); }else { $("#process_page").hide(); $(".again").show(); } } }) } $(".again-btn").click(function() { initData(); getQuestionsData().then(function(v) { console.log(v) questionsData = v ; currData= questionsData[currnum-1]; $("#start_page").hide(); $("#process_page").show(); updateQuestion(); answer(); }) }) $(".over-btn").click(function() { initData() $("#game").hide(); }) function initData() { questionsData =[]; currData = []; correctnum = 0; currnum = 1; $(".process").hide(); $(".start").show(); } $('html').click(function(){ $("#guide").hide(); })