Fix total time counting for timed questions and lots of cleanup
This commit is contained in:
parent
6cdf7dbb4d
commit
314c9e8c67
|
@ -2,7 +2,7 @@ ChooseAny Which Materials can be used to fabricate the brake pedal? "Steel
|
||||||
Aluminium
|
Aluminium
|
||||||
Titanum
|
Titanum
|
||||||
All the above" "1
|
All the above" "1
|
||||||
2" 3
|
2" 0.3
|
||||||
ChooseOne What is depicted on the picture "7 speed double clutch transmission for AWD
|
ChooseOne What is depicted on the picture "7 speed double clutch transmission for AWD
|
||||||
8 speed double clutch transmission for AWD
|
8 speed double clutch transmission for AWD
|
||||||
7 speed double clutch transmission for 2WD
|
7 speed double clutch transmission for 2WD
|
||||||
|
|
|
41
web/quiz.js
41
web/quiz.js
|
@ -16,7 +16,7 @@ function updateFSATeamCountTroll() {
|
||||||
var time = state.questions[state.currentQuestion].time || state.submitTime
|
var time = state.questions[state.currentQuestion].time || state.submitTime
|
||||||
var timeratio = 1 - (state.submitTimer / time)
|
var timeratio = 1 - (state.submitTimer / time)
|
||||||
var slowAnswerChance = Math.random()*2*Math.pow(timeratio, 2)
|
var slowAnswerChance = Math.random()*2*Math.pow(timeratio, 2)
|
||||||
var quickAnswerChance = (Math.random()+Math.sqrt(69/time))/3
|
var quickAnswerChance = (Math.random()+Math.sqrt(69/time))/4
|
||||||
var chance = Math.round(slowAnswerChance + quickAnswerChance)
|
var chance = Math.round(slowAnswerChance + quickAnswerChance)
|
||||||
var magnitude = Math.round((Math.random()/2+timeratio)*6)
|
var magnitude = Math.round((Math.random()/2+timeratio)*6)
|
||||||
var nt = chance * magnitude
|
var nt = chance * magnitude
|
||||||
|
@ -31,9 +31,10 @@ function updateTotalTimer() {
|
||||||
var timerEls = document.querySelectorAll('.totaltimer')
|
var timerEls = document.querySelectorAll('.totaltimer')
|
||||||
|
|
||||||
for (timerEl of timerEls)
|
for (timerEl of timerEls)
|
||||||
timerEl.innerHTML = formatTime(state.totalTimer);
|
timerEl.innerHTML = 'Total time: ' + formatTime(state.totalTimer);
|
||||||
|
|
||||||
state.totalTimer++
|
if (!state.waitNextQuestion)
|
||||||
|
state.totalTimer++
|
||||||
|
|
||||||
localStorage.setItem('state', JSON.stringify(state))
|
localStorage.setItem('state', JSON.stringify(state))
|
||||||
|
|
||||||
|
@ -123,7 +124,7 @@ function startSubmitTimer(time) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function showSequentialQuestion(n) {
|
function updateSequentialQuestion() {
|
||||||
|
|
||||||
var questions = document.querySelectorAll('.question')
|
var questions = document.querySelectorAll('.question')
|
||||||
for (q of questions)
|
for (q of questions)
|
||||||
|
@ -131,8 +132,8 @@ function showSequentialQuestion(n) {
|
||||||
|
|
||||||
updateSubmitInfo()
|
updateSubmitInfo()
|
||||||
|
|
||||||
if (n !== null) {
|
if (state.currentQuestion !== null && !state.waitNextQuestion) {
|
||||||
var q = document.querySelector('#quiz form #question' + n)
|
var q = document.querySelector('#quiz form #question' + state.currentQuestion)
|
||||||
q.style.display = 'block'
|
q.style.display = 'block'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,10 +144,17 @@ function nextQuestion() {
|
||||||
// Save time taken
|
// Save time taken
|
||||||
state.questions[state.currentQuestion].timeTaken = state.totalTimer - state.questionStartTotalTimer
|
state.questions[state.currentQuestion].timeTaken = state.totalTimer - state.questionStartTotalTimer
|
||||||
|
|
||||||
if (getRule('questionTimeout') && (state.submitTimer > 0)
|
// Last question
|
||||||
&& (state.currentQuestion != (state.questions.length-1))) {
|
if (state.currentQuestion == (state.questions.length - 1)) {
|
||||||
|
state.currentQuestion = null
|
||||||
|
updateSequentialQuestion()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Waiting for next question
|
||||||
|
if (getRule('questionTimeout') && (state.submitTimer > 0)) {
|
||||||
state.waitNextQuestion = true;
|
state.waitNextQuestion = true;
|
||||||
showSequentialQuestion(null) // hide question
|
updateSequentialQuestion() // hide question
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,12 +170,9 @@ function nextQuestion() {
|
||||||
|
|
||||||
state.currentQuestion++
|
state.currentQuestion++
|
||||||
|
|
||||||
if (state.currentQuestion == state.questions.length)
|
updateSequentialQuestion()
|
||||||
state.currentQuestion = null
|
|
||||||
|
|
||||||
showSequentialQuestion(state.currentQuestion)
|
if (getRule('questionTimeout'))
|
||||||
|
|
||||||
if (state.currentQuestion !== null && getRule('questionTimeout'))
|
|
||||||
startSubmitTimer()
|
startSubmitTimer()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -232,7 +237,7 @@ function startQuiz() {
|
||||||
changeView('quiz')
|
changeView('quiz')
|
||||||
|
|
||||||
if (getRule('sequential'))
|
if (getRule('sequential'))
|
||||||
showSequentialQuestion(state.currentQuestion)
|
updateSequentialQuestion()
|
||||||
|
|
||||||
if (state.submitTimer > 0)
|
if (state.submitTimer > 0)
|
||||||
startSubmitTimer(state.submitTimer)
|
startSubmitTimer(state.submitTimer)
|
||||||
|
@ -373,13 +378,15 @@ function showQuizResults() {
|
||||||
qinfo += ('. Time taken: ' + formatTime(q.timeTaken))
|
qinfo += ('. Time taken: ' + formatTime(q.timeTaken))
|
||||||
if (value.correct && getRule('allowQOvertime'))
|
if (value.correct && getRule('allowQOvertime'))
|
||||||
qinfo += (', Bonus points ' + ((q.timeTaken <= q.time) ? 'received' : 'lost'))
|
qinfo += (', Bonus points ' + ((q.timeTaken <= q.time) ? 'received' : 'lost'))
|
||||||
else if (q.timeTaken == q.time)
|
else if (q.timeTaken >= (q.time - 1) && !getRule('allowQOvertime'))
|
||||||
qinfo += ', Time ran out'
|
qinfo += ', Time ran out'
|
||||||
}
|
}
|
||||||
el.querySelector('h3').innerHTML += ` <span class="meta">${qinfo}</span>`
|
el.querySelector('h3').innerHTML += ` <span class="meta">${qinfo}</span>`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.querySelector('#fsateamcounttroll').innerHTML = ''
|
||||||
|
document.querySelector('#submitinfo').innerHTML = ''
|
||||||
document.querySelector('#quizSubmitButton').value = 'Back'
|
document.querySelector('#quizSubmitButton').value = 'Back'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -468,7 +475,7 @@ function submitQuiz() {
|
||||||
renderQuiz()
|
renderQuiz()
|
||||||
if (getRule('sequential')) {
|
if (getRule('sequential')) {
|
||||||
state.currentQuestion = 0
|
state.currentQuestion = 0
|
||||||
showSequentialQuestion(state.currentQuestion)
|
updateSequentialQuestion()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getRule('submitTimeout'))
|
if (getRule('submitTimeout'))
|
||||||
|
|
Loading…
Reference in New Issue