Added quit button.
This commit is contained in:
1 parent
247839aa35
commit
7f9cfc6d8a
1 file changed
+12
@@ -80,6 +80,7 @@ def generate_html(questions):
|
|||||||
.question-box {{ background: #fff; padding: 1rem; border-radius: 8px; box-shadow: 0 0 10px rgba(0,0,0,0.1); margin-bottom: 2rem; }}
|
.question-box {{ background: #fff; padding: 1rem; border-radius: 8px; box-shadow: 0 0 10px rgba(0,0,0,0.1); margin-bottom: 2rem; }}
|
||||||
.answers label {{ display: block; margin: 0.5rem 0; }}
|
.answers label {{ display: block; margin: 0.5rem 0; }}
|
||||||
.nav-buttons {{ margin-top: 1rem; }}
|
.nav-buttons {{ margin-top: 1rem; }}
|
||||||
|
.nav-buttons button {{ margin-right: 0.5rem; }}
|
||||||
.correct {{ color: green; }}
|
.correct {{ color: green; }}
|
||||||
.incorrect {{ color: red; }}
|
.incorrect {{ color: red; }}
|
||||||
#result {{ font-weight: bold; }}
|
#result {{ font-weight: bold; }}
|
||||||
@@ -113,6 +114,7 @@ def generate_html(questions):
|
|||||||
document.getElementById("quiz").innerHTML = `<h2>Finished!</h2><p id="result">Score: ${{score}} / ${{shuffled.length}} (${{((score / shuffled.length) * 100).toFixed(2)}}%)</p>`;
|
document.getElementById("quiz").innerHTML = `<h2>Finished!</h2><p id="result">Score: ${{score}} / ${{shuffled.length}} (${{((score / shuffled.length) * 100).toFixed(2)}}%)</p>`;
|
||||||
return;
|
return;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
const q = shuffled[current];
|
const q = shuffled[current];
|
||||||
const options = q.answers.map((a, i) => {{
|
const options = q.answers.map((a, i) => {{
|
||||||
return `<label><input type="radio" name="ans" value="${{i}}"> ${{a}}</label>`;
|
return `<label><input type="radio" name="ans" value="${{i}}"> ${{a}}</label>`;
|
||||||
@@ -124,6 +126,7 @@ def generate_html(questions):
|
|||||||
<p>${{q.question}}</p>
|
<p>${{q.question}}</p>
|
||||||
<div class="answers">${{options}}</div>
|
<div class="answers">${{options}}</div>
|
||||||
<div class="nav-buttons">
|
<div class="nav-buttons">
|
||||||
|
<button onclick="quitTest()">Quit</button>
|
||||||
<button onclick="submitAnswer(${{q.correct}})">Submit</button>
|
<button onclick="submitAnswer(${{q.correct}})">Submit</button>
|
||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
@@ -156,6 +159,15 @@ def generate_html(questions):
|
|||||||
showQuestion();
|
showQuestion();
|
||||||
}}, isCorrect ? 1000 : 2500);
|
}}, isCorrect ? 1000 : 2500);
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
function quitTest() {{
|
||||||
|
const answered = current;
|
||||||
|
const percent = answered > 0 ? ((score / answered) * 100).toFixed(0) : 0;
|
||||||
|
document.getElementById("quiz").innerHTML = `
|
||||||
|
<h1>Test Score</h1>
|
||||||
|
<p>You answered ${{score}} questions correctly out of ${{answered}} questions answered. (${{percent}}%)</p>
|
||||||
|
`;
|
||||||
|
}}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in new issue
Block a user