document.addEventListener('DOMContentLoaded', async () => { const app = document.getElementById('app'); const resp = await fetch('/api/generate'); const data = await resp.json(); if (data.error) { app.innerHTML = `
Ошибка получения теста: ${data.error}
`; return; } if (!Array.isArray(data) || data.length === 0) { app.innerHTML = `Нет данных
`; return; } const questions = data; let current = 0; const answers = new Array(questions.length).fill(null); function renderQuestion(i) { const q = questions[i]; const opts = q.options || []; const html = `Вопрос ${i+1}: ${q.question}
Результат: ${percent}% – ${verdict}