Bird Song Identification Quiz Generator
Define species and audio sources to generate an interactive identification quiz.
1. Add Species and Audio Source
*Note: Due to environment constraints, audio playback requires valid external URLs in a live browser. This tool only stores the URL data.
2. Current Species Database
Bird Song Identification Quiz
Question 1 of 0 | Score: 0
Add species to the database to build a quiz.
'; return; } speciesDatabase.forEach(s => { const item = document.createElement('div'); item.className = 'bsiqg-list-item bg-white border-l-4 border-green-400 rounded-lg'; item.innerHTML = ` ${escapeHtml(s.name)} ${escapeHtml(s.url)} `; list.appendChild(item); }); } // --- Quiz Logic --- function shuffleArray(array) { for (let i = array.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } return array; } function bsiqgGenerateQuestions() { if (speciesDatabase.length < 4) { return []; // Need at least 4 species for a good multiple-choice quiz } // Use a random subset of 10 or all if less than 10 let availableSpecies = shuffleArray([...speciesDatabase]); const numQuestions = Math.min(10, availableSpecies.length); const questions = []; for (let i = 0; i < numQuestions; i++) { const correctSpecies = availableSpecies[i]; // Get 3 random wrong answers (decoys) let decoys = availableSpecies.filter(s => s.id !== correctSpecies.id); shuffleArray(decoys); decoys = decoys.slice(0, 3); // Create options let options = [...decoys.map(s => ({ species: s.name, correct: false })), { species: correctSpecies.name, correct: true }]; shuffleArray(options); questions.push({ correctSpecies: correctSpecies.name, audioUrl: correctSpecies.url, options: options }); } return questions; } window.bsiqgStartQuiz = function() { const questions = bsiqgGenerateQuestions(); if (questions.length < 4) { document.getElementById('quiz-content').innerHTML = `You need at least 4 species in the database to generate a quiz with decoys. Please add more species.
`; document.getElementById('quiz-total-q').textContent = 0; document.getElementById('quiz-score').textContent = 0; return; } currentQuiz.questions = questions; currentQuiz.currentQIndex = 0; currentQuiz.score = 0; currentQuiz.answered = false; document.getElementById('quiz-total-q').textContent = currentQuiz.questions.length; document.getElementById('quiz-score').textContent = currentQuiz.score; bsiqgRenderQuestion(); }; function bsiqgRenderQuestion() { if (currentQuiz.currentQIndex >= currentQuiz.questions.length) { bsiqgRenderResults(); return; } const qData = currentQuiz.questions[currentQuiz.currentQIndex]; const contentDiv = document.getElementById('quiz-content'); document.getElementById('quiz-current-q').textContent = currentQuiz.currentQIndex + 1; document.getElementById('quiz-next-btn').disabled = true; currentQuiz.answered = false; let optionsHtml = qData.options.map((option, index) => ` `).join(''); contentDiv.innerHTML = `Identify the species making the following sound:
If audio does not play, check browser console for potential URL or CORS errors.
${optionsHtml}
Quiz Complete!
Your Final Score:
${score} / ${total}
(${percentage}%)
