Space Quiz – Sequential Flow
Space Quiz
Quiz Results
Name:
Email:
Time Taken: 0:00
You completed the quiz in ${timeString} minutes.
Your accuracy rate is ${accuracy}% for attempted questions.
${notAttempted > 0 ? `You left ${notAttempted} questions unanswered.
` : ''}
${getPerformanceAdvice(percentage, notAttempted, accuracy)}
`;
summary.innerHTML = summaryHTML;
}
// Helper function for performance advice
function getPerformanceAdvice(percentage, notAttempted, accuracy) {
if (notAttempted > 0) {
return "Try to attempt all questions next time, even if you're not completely sure of the answer.";
} else if (percentage >= 90) {
return "Excellent work! You've shown a great understanding of the subject matter.";
} else if (percentage >= 70) {
return "Good job! With a bit more practice, you can improve even further.";
} else if (percentage >= 50) {
return "You're on the right track. Focus on the topics you got wrong to improve your score.";
} else {
return "Don't worry! Review the topics you struggled with and try again. Practice makes perfect!";
}
}
// PDF download function
function downloadResults() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
let yPosition = 20;
const leftMargin = 20;
const lineHeight = 10;
const websiteURL = "acadpills.com";
const timestamp = new Date().toLocaleString();
const pageCount = doc.getNumberOfPages();
doc.setFontSize(10);
for (let i = 1; i <= pageCount; i++) {
doc.setPage(i);
const footerText = `This test is conducted on ${websiteURL} and result is Generated on: ${timestamp}`;
const textWidth = doc.getTextWidth(footerText);
const pageWidth = doc.internal.pageSize.width;
// Center align the footer text
doc.text(footerText, (pageWidth - textWidth) / 2, doc.internal.pageSize.height - 10);
}
// Function to add footer on every page
function addFooter(pageNumber, totalPages) {
const pageHeight = doc.internal.pageSize.height;
const timestamp = new Date().toLocaleString(); // Get current date and time
const footerText = `This test is conducted on ${websiteURL} and result is Generated on: ${timestamp}`;
doc.setFontSize(10);
doc.text(footerText, leftMargin, pageHeight - 10);
}
// Add title
doc.setFontSize(20);
doc.setTextColor(76, 175, 80);
doc.text("Quiz Results Summary", leftMargin, yPosition);
doc.setFontSize(12);
doc.setTextColor(0, 0, 0);
yPosition += lineHeight * 2;
// Add participant details
const name = document.getElementById('resultName').textContent;
const email = document.getElementById('resultEmail').textContent;
const timeTaken = document.getElementById('timeTaken').textContent;
doc.setFontSize(14);
doc.text("Participant Details", leftMargin, yPosition);
yPosition += lineHeight;
doc.setFontSize(12);
doc.text(`Name: ${name}`, leftMargin, yPosition);
yPosition += lineHeight;
doc.text(`Email: ${email}`, leftMargin, yPosition);
yPosition += lineHeight;
doc.text(`Time Taken: ${timeTaken}`, leftMargin, yPosition);
yPosition += lineHeight * 2;
// Add performance metrics
const total = document.getElementById('totalQuestions').textContent;
const attempted = document.getElementById('attempted').textContent;
const correct = document.getElementById('correctCount').textContent;
const wrong = document.getElementById('wrongCount').textContent;
const notAttempted = document.getElementById('notAttempted').textContent;
const accuracy = document.getElementById('accuracy').textContent;
const percentage = document.getElementById('percentageText').textContent;
doc.setFontSize(14);
doc.text("Performance Metrics", leftMargin, yPosition);
yPosition += lineHeight;
doc.setFontSize(12);
doc.text(`Total Questions: ${total}`, leftMargin, yPosition);
yPosition += lineHeight;
doc.text(`Attempted: ${attempted}`, leftMargin, yPosition);
yPosition += lineHeight;
doc.text(`Correct Answers: ${correct}`, leftMargin, yPosition);
yPosition += lineHeight;
doc.text(`Wrong Answers: ${wrong}`, leftMargin, yPosition);
yPosition += lineHeight;
doc.text(`Not Attempted: ${notAttempted}`, leftMargin, yPosition);
yPosition += lineHeight;
doc.text(`Accuracy: ${accuracy}`, leftMargin, yPosition);
yPosition += lineHeight;
doc.text(`Overall Score: ${percentage}`, leftMargin, yPosition);
yPosition += lineHeight * 2;
// Add detailed question analysis
doc.setFontSize(14);
doc.text("Question Details", leftMargin, yPosition);
yPosition += lineHeight;
doc.setFontSize(12);
let pageNumber = 1;
const totalPages = Math.ceil((questions.length * 5 + yPosition) / doc.internal.pageSize.height);
questions.forEach((q, i) => {
if (yPosition > 250) {
doc.addPage();
yPosition = 20;
}
const answer = userAnswers[i];
const questionStatus = answer ?
(answer.isCorrect ? ' Correct' : ' Incorrect') :
'Not attempted';
const statusColor = answer ?
(answer.isCorrect ? [0, 128, 0] : [255, 0, 0]) :
[128, 128, 128];
// Continue from where the previous code left off...
doc.text(`Question ${i + 1}: ${q.question}`, leftMargin, yPosition);
yPosition += lineHeight;
doc.text(`Correct Answer: ${q.options[q.correct]}`, leftMargin + 5, yPosition);
yPosition += lineHeight;
doc.text(`Your Answer: ${answer ?
(answer.selected >= 0 ? q.options[answer.selected] : 'Not attempted') :
'Not attempted'}`, leftMargin + 5, yPosition);
yPosition += lineHeight;
doc.setTextColor(statusColor[0], statusColor[1], statusColor[2]);
doc.text(`Status: ${questionStatus}`, leftMargin + 5, yPosition);
doc.setTextColor(0, 0, 0);
yPosition += lineHeight * 1.5;
});
// Add footer with timestamp
//const timestamp = new Date().toLocaleString();
doc.setFontSize(10);
doc.text(`This test is conducted on ${websiteURL} and result is Generated on: ${timestamp}`, leftMargin, doc.internal.pageSize.height - 10);
addFooter(pageNumber, totalPages);
// Save the PDF
const fileName = `quiz_results_${name.replace(/\s+/g, '_')}.pdf`;
doc.save(fileName);
}
// Function to show detailed answers
function showAnswers() {
const answersList = document.getElementById('answersList');
answersList.innerHTML = '';
questions.forEach((q, index) => {
const answer = document.createElement('div');
answer.className = 'answer-item';
const userAnswer = userAnswers[index];
answer.innerHTML = `
Question ${index + 1}: ${q.question}
Correct Answer: ${q.options[q.correct]}
${userAnswer ?
`Your Answer: ${userAnswer.selected >= 0 ? q.options[userAnswer.selected] : 'Not attempted'}
` :
'Not attempted
'}
`;
answersList.appendChild(answer);
});
document.getElementById('answersModal').style.display = 'block';
}
// Function to close answers modal
function closeAnswers() {
document.getElementById('answersModal').style.display = 'none';
}
// Function to restart quiz
function restartQuiz() {
// Hide results container
resultsContainer.classList.add('hidden');
// Show quiz container
quizContainer.classList.remove('hidden');
// Reset quiz state
currentQuestionIndex = 0;
coin = 0;
userAnswers = [];
document.getElementById('coin').textContent = '0';
// Start quiz immediately with existing user details
quizStartTime = Date.now();
loadQuestion(0);
startTimer();
}
// Function to go back to home
function goToHome() {
// Hide results container
resultsContainer.classList.add('hidden');
// Show user form
userForm.classList.remove('hidden');
// Reset quiz state
currentQuestionIndex = 0;
coin = 0;
userAnswers = [];
quizStartTime = 0;
quizEndTime = 0;
questionStartTimes = {};
// Reset form fields
document.getElementById('userName').value = '';
document.getElementById('userEmail').value = '';
document.getElementById('coin').textContent = '0';
}
// Initialize the quiz when the page loads
document.addEventListener('DOMContentLoaded', initializeQuiz);