${challenge.description}
`;
listEl.appendChild(card);
});
}
}
window.updateChallenge = function(id, field, value) {
const challenge = challenges.find(c => c.id === id);
if (challenge) {
challenge[field] = value;
saveChallenges();
}
};
window.toggleStatus = function(id) {
const challenge = challenges.find(c => c.id === id);
if (challenge) {
challenge.status = challenge.status === 'Open' ? 'Resolved' : 'Open';
saveChallenges();
renderChallenges();
}
};
window.deleteChallenge = function(id) {
if (confirm('Are you sure you want to delete this challenge log?')) {
challenges = challenges.filter(c => c.id !== id);
saveChallenges();
renderChallenges();
}
};
window.changeTab = function(tabIndex) {
const tabs = document.querySelectorAll('.tab');
const tabContents = document.querySelectorAll('.tab-content');
tabs[currentTabIndex].classList.remove('active');
tabContents[currentTabIndex].classList.remove('active');
currentTabIndex = tabIndex;
tabs[currentTabIndex].classList.add('active');
tabContents[currentTabIndex].classList.add('active');
if (tabIndex === 1) {
renderChallenges();
}
};
window.downloadPDF = function() {
if (challenges.length === 0) {
alert("There are no challenges to download.");
return;
}
const { jsPDF } = window;
const doc = new jsPDF();
doc.setFontSize(20);
doc.text("Learning Challenges Report", 14, 22);
const tableBody = challenges.map(c => [
c.date,
c.subject,
c.status,
c.description,
c.strategy,
c.solution
]);
doc.autoTable({
head: [['Date', 'Subject', 'Status', 'Challenge', 'Strategy', 'Solution']],
body: tableBody,
startY: 30,
theme: 'grid',
styles: { fontSize: 8 },
headStyles: { fillColor: [79, 70, 229] }, // Indigo color for header
columnStyles: {
3: { cellWidth: 'auto' },
4: { cellWidth: 'auto' },
5: { cellWidth: 'auto' }
}
});
doc.save('learning_challenges_report.pdf');
};
// Initial Load
loadChallenges();
});