Bad Breath (Halitosis) Risk Analyzer

Step 1: Oral Hygiene & Dietary Habits

This analyzer is an educational tool, not a substitute for a diagnosis from a dentist or physician.

${question.text}

${optionsHTML}
`; } function populateQuestions() { const hygieneContainer = document.getElementById('hygiene-diet-questions'); hygieneContainer.innerHTML = questions.hygieneDiet.map(createQuestionHTML).join(''); const lifestyleContainer = document.getElementById('lifestyle-health-questions'); lifestyleContainer.innerHTML = questions.lifestyleHealth.map(createQuestionHTML).join(''); } function updateUI() { tabs.forEach((tab, index) => { tab.classList.toggle('hidden', index + 1 !== currentTab); tab.classList.toggle('absolute', index + 1 !== currentTab); tab.classList.toggle('relative', index + 1 === currentTab); }); tabBtns.forEach((btn, index) => { btn.classList.toggle('tab-active', index + 1 === currentTab); btn.classList.toggle('tab-inactive', index + 1 !== currentTab); }); prevBtn.classList.toggle('invisible', currentTab === 1); nextBtn.textContent = currentTab === 2 ? 'Analyze Risk' : 'Next'; nextBtn.classList.toggle('hidden', currentTab >= 3); } window.changeTab = (tabNumber) => { currentTab = tabNumber; updateUI(); }; function analyzeRisk() { let score = 0; const userAnswers = {}; const allQuestions = [...questions.hygieneDiet, ...questions.lifestyleHealth]; allQuestions.forEach(q => { const selectedOption = document.querySelector(`input[name="${q.id}"]:checked`); score += parseInt(selectedOption.value); userAnswers[q.id] = { question: q.text, answer: selectedOption.nextElementSibling.textContent, points: parseInt(selectedOption.value) }; }); let riskLevel, riskPercent, barColor, summary, recommendations = []; if (score <= 5) { riskLevel = 'Low Risk'; riskPercent = 25; barColor = 'bg-green-500'; summary = 'Your habits suggest a low risk for chronic halitosis. Keep up the great work!'; } else if (score <= 12) { riskLevel = 'Moderate Risk'; riskPercent = 60; barColor = 'bg-yellow-500'; summary = 'Your results indicate a moderate risk for halitosis. Some of your habits could be contributing factors.'; } else { riskLevel = 'High Risk'; riskPercent = 95; barColor = 'bg-red-600'; summary = 'Your profile suggests a high risk for chronic halitosis. Several factors are likely contributing, and improvements to your routine are strongly recommended.'; } // Personalized recommendations if (userAnswers.brushing.points > 0) recommendations.push('Brush your teeth thoroughly twice a day for two minutes.'); if (userAnswers.flossing.points > 0) recommendations.push('Floss daily to remove plaque and food particles between teeth.'); if (userAnswers.tongue.points > 0) recommendations.push('Clean your tongue daily with a scraper or brush to remove bacteria.'); if (userAnswers.hydration.points > 0) recommendations.push('Increase your daily water intake to help prevent dry mouth.'); if (userAnswers.smoking.points > 0) recommendations.push('Consider quitting smoking, as it is a major cause of bad breath.'); if (userAnswers.dryMouth.points > 0) recommendations.push('Discuss your dry mouth symptoms with a dentist or doctor, as it can be a significant factor.'); if (recommendations.length === 0) recommendations.push('Continue your excellent oral hygiene and lifestyle habits.'); return { userAnswers, riskLevel, riskPercent, barColor, summary, recommendations }; } function handleAnalysis() { const results = analyzeRisk(); riskBar.style.width = `${results.riskPercent}%`; riskBar.className = `h-10 text-center text-white font-bold flex items-center justify-center transition-all duration-500 ease-out ${results.barColor}`; setTimeout(() => { riskLevelText.textContent = results.riskLevel; riskLevelText.classList.remove('opacity-0'); }, 500); riskSummary.textContent = results.summary; recommendationsList.innerHTML = results.recommendations.map(rec => `
  • ${rec}
  • `).join(''); resultsPlaceholder.classList.add('hidden'); resultsContent.classList.remove('hidden'); currentTab = 3; updateUI(); } function downloadPDF() { if (resultsContent.classList.contains('hidden')) { alert('Please analyze your risk first.'); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF({ unit: 'pt', format: 'a4' }); const pageW = doc.internal.pageSize.getWidth(); const margin = 40; let currentY = 0; const results = analyzeRisk(); const primaryColor = [37, 99, 235], grayColor = [107, 114, 128], blackColor = [17, 24, 39]; doc.setFillColor(...primaryColor); doc.rect(0, 0, pageW, 80, 'F'); doc.setFont('helvetica', 'bold'); doc.setFontSize(24); doc.setTextColor(255, 255, 255); doc.text('Halitosis Risk Assessment Report', margin, 50); currentY = 110; const riskColorMap = { 'Low Risk': [4, 120, 87], 'Moderate Risk': [217, 119, 6], 'High Risk': [220, 38, 38] }; const riskColor = riskColorMap[results.riskLevel]; doc.setFont('helvetica', 'bold'); doc.setFontSize(14); doc.setTextColor(...blackColor); doc.text('Overall Assessment', margin, currentY); currentY += 20; doc.setFontSize(12); doc.text('Estimated Risk Level:', margin, currentY); doc.setTextColor(...riskColor); doc.setFont('helvetica', 'bold'); doc.text(results.riskLevel.toUpperCase(), margin + 120, currentY); currentY += 25; doc.setTextColor(...blackColor); doc.setFont('helvetica', 'normal'); doc.setFontSize(10); const summaryLines = doc.splitTextToSize(results.summary, pageW - (margin * 2)); doc.text(summaryLines, margin, currentY); currentY += (summaryLines.length * 12) + 20; const tableData = Object.values(results.userAnswers).map(ans => [ans.question, ans.answer]); doc.autoTable({ startY: currentY, head: [['Factor', 'Your Answer']], body: tableData, theme: 'striped', headStyles: { fillColor: [59, 130, 246] }, styles: { font: 'helvetica', fontSize: 9 } }); currentY = doc.lastAutoTable.finalY + 30; doc.setFont('helvetica', 'bold'); doc.setFontSize(12); doc.text('Personalized Recommendations', margin, currentY); currentY += 15; doc.setFont('helvetica', 'normal'); doc.setFontSize(9); results.recommendations.forEach(rec => { const recLines = doc.splitTextToSize(`• ${rec}`, pageW - (margin * 2)); doc.text(recLines, margin, currentY); currentY += (recLines.length * 10) + 5; }); const pageH = doc.internal.pageSize.getHeight(); doc.setDrawColor(...grayColor); doc.line(margin, pageH - 60, pageW - margin, pageH - 60); doc.setFont('helvetica', 'normal'); doc.setFontSize(8); doc.setTextColor(...grayColor); const footerText = 'This report is for educational purposes only. Chronic bad breath can be a sign of underlying health issues. Consult a dentist or physician for a complete diagnosis.'; doc.text(doc.splitTextToSize(footerText, pageW - (margin * 2)), margin, pageH - 45); doc.save('Halitosis-Risk-Assessment.pdf'); } // --- EVENT LISTENERS --- prevBtn.addEventListener('click', () => { if (currentTab > 1) { currentTab--; updateUI(); } }); nextBtn.addEventListener('click', () => { if (currentTab === 1) { currentTab++; } else if (currentTab === 2) { handleAnalysis(); } updateUI(); }); pdfDownloadBtn.addEventListener('click', downloadPDF); // --- KICKOFF --- populateQuestions(); updateUI(); });
    Scroll to Top