e viết hàm này để setTimeout đếm ngược thời gian được trả về từ server
function countDownTime(time){
var timeFull=time*60*1000;
var minutes = Math.floor((timeFull%(1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((timeFull%(1000*60)) / 1000);
document.getElementById('m').innerText = minutes.toString();
document.getElementById('s').innerText = seconds.toString();
if (seconds === -1){
minutes -= 1;
seconds ==59;
}
setTimeout(function(){
seconds--;
countDownTime(time);
}, 1000);
}
xong em gọi nó vào hàm này nhưng nó báo lỗi.
if(!(surveyObj && surveyObj.listQuestion.length > 0)){
return;
}
countDownTime(surveyObj.surveyTime);
console.log(surveyObj);
if(surveyObj.random==true){
shuffle(surveyObj.listQuestion);
}
console.log(surveyObj);
var htmlArr = [];
htmlArr.push('<div id="survey-id" style="display:none">'+surveyObj.testId+'</div>');
htmlArr.push('<div id="survey-name"><h2>'+surveyObj.name+'</h2></div>');
htmlArr.push('<div class="timeout" float:right><span>Thời gian còn lại: </span><span id="m">Phút</span> : <span id="s">Giây</span></div>');
console.log(surveyObj.surveyTime);
htmlArr.push('<div class="question-list">');
surveyObj.listQuestion.forEach(question=>{
htmlArr.push('<div id="'+question.questionId+'" class="question">');
htmlArr.push('<h3>'+question.content+'</h3>');
htmlArr.push('<div class="answer-list">');
question.listAnswer.forEach(answer=>{
htmlArr.push('<div class="answer">');
htmlArr.push('<input type="checkbox" class="answer-input" id="answer-'+answer.answerId+'" value="'+answer.answerId+'" onchange="answerAs('+question.questionId+','+ answer.answerId+')"> ');
htmlArr.push('<label for="answer-'+answer.answerId+'">'+answer.content+'</label>');
htmlArr.push('</div>');
});
htmlArr.push('</div>');
htmlArr.push('</div>');
})
htmlArr.push('</div>');
console.log(resultObject);
htmlArr.push('<button class="btn btn-success btn-next" type="button" data-index="0">Tiếp theo</button>');
htmlArr.push('<button class="btn btn-success btn-finish" type="button" style="display:none;">Hoàn thành</button>');
jQuery('#survey').append(htmlArr.join('\n'));