`;
this.dom.questionList.appendChild(item);
});
document.querySelectorAll('.delete-btn').forEach(btn => {
btn.addEventListener('click', (e) => this.deleteQuestion(Number(e.currentTarget.dataset.id)));
});
},
renderAll() {
this.renderManageList();
this.startQuiz();
},
changeTab(tabIndex) {
this.dom.tabButtons[this.currentTab].classList.remove('active');
this.dom.tabContents[this.currentTab].classList.remove('active');
this.currentTab = tabIndex;
this.dom.tabButtons[this.currentTab].classList.add('active');
this.dom.tabContents[this.currentTab].classList.add('active');
},
generatePdf() {
if (this.questions.length === 0) {
alert("Cannot generate a PDF for an empty question bank.");
return;
}
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ unit: 'pt', format: 'a4' });
pdf.setFontSize(22);
pdf.text("Quiz Question Bank", 40, 60);
pdf.setFontSize(12);
let yPos = 100;
const margin = 40;
const pageHeight = pdf.internal.pageSize.getHeight();
this.questions.forEach((q, index) => {
const textLines = pdf.splitTextToSize(`Q${index + 1}: ${q.text}`, 515);
const answerLine = `Correct Answer: ${q.correct}`;
if (yPos + (textLines.length * 15) + 30 > pageHeight) {
pdf.addPage();
yPos = 40;
}
pdf.setFont('helvetica', 'bold');
pdf.text(textLines, margin, yPos);
yPos += (textLines.length * 15);
pdf.setFont('helvetica', 'normal');
pdf.text(answerLine, margin + 15, yPos);
yPos += 40;
});
pdf.save('Quiz-Question-Bank.pdf');
},
};
window.app = {
changeTab: app.changeTab.bind(app),
};
app.init();
});
