<title>Ngā Kararehe</title>
body { font-family: Arial, sans-serif; padding: 20px; }
/* ================= DROPDOWN ================= */
#category-selector select {
/* ================= FLASHCARDS ================= */
#flashcards-section .card {
transition: transform 0.6s, background-color 0.6s;
background-color: lightyellow;
#flashcards-section .card.flipped {
background-color: lightblue;
/* ================= QUIZ ================= */
#quiz-section .quiz-question {
#quiz-section .quiz-question button {
/* ================= MATCHING ================= */
justify-content: space-between;
background-color: #fafafa;
#matching-section .drag-item {
.pair .sep { font-weight: bold; }
<div id="category-selector">
<label for="category">Select Category: </label>
<select id="category" onchange="updateContent()">
<option value="pets">🐶 Pets – Ngā kararehe mōkai</option>
<option value="wild">🦁 Wild Animals – Ngā kararehe taiao</option>
<option value="farm">🐄 Farm Animals – Ngā kararehe pāmu</option>
<option value="birds">🐦 Native Birds – Ngā manu māori</option>
<div id="flashcards-section"></div>
<div id="quiz-section"></div>
<h3>Matching - CLICK - CLICK</h3>
<div id="matching-section"></div>
// Vocabulary data organized by categories
["arawhana", "elephant"],
["rīno mā", "white rhino"],
["kererū", "wood pigeon"],
["kākā", "native parrot"],
["kākāpō", "ground parrot"],
["kākāriki", "parakeet"],
["kōtare", "kingfisher"],
["pīwakawaka", "fantail"],
["kākāriki karaka", "orange-fronted parakeet"],
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]];
/* ========== FLASHCARDS ========== */
function showFlashcards(category) {
const container = document.getElementById('flashcards-section');
container.innerHTML = '';
const categoryData = data[category] || [];
if (categoryData.length === 0) return container.textContent = 'No data found';
const shuffled = shuffleArray([...categoryData]);
for (let row of shuffled) {
if (uniqueCards.length >= 12) break;
uniqueCards.forEach(row => {
const card = document.createElement('div');
card.textContent = row[0];
if (!card.classList.contains('flipped')) {
card.classList.add('flipped');
card.textContent = row[1];
card.classList.remove('flipped');
card.textContent = row[0];
container.appendChild(card);
/* ========== QUIZ ========== */
function showQuiz(category) {
const container = document.getElementById('quiz-section');
container.innerHTML = '';
const categoryData = data[category] || [];
if (categoryData.length === 0) return container.textContent = 'No data found';
const shuffled = shuffleArray([...categoryData]);
const questions = shuffled.slice(0, Math.min(12, shuffled.length));
questions.forEach((row, i) => {
const qDiv = document.createElement('div');
qDiv.className = 'quiz-question';
qDiv.innerHTML = `<b>Q${i+1}: ${row[0]}</b><br>`;
while (distractors.length < 3) {
const r = categoryData[Math.floor(Math.random() * categoryData.length)][1];
if (r !== row[1] && !distractors.includes(r)) distractors.push(r);
const options = shuffleArray([row[1], ...distractors]);
const btn = document.createElement('button');
if (btn.disabled) return;
btn.style.backgroundColor = 'lightgreen';
btn.style.backgroundColor = 'lightcoral';
[...qDiv.querySelectorAll('button')].forEach(b => b.disabled = true);
container.appendChild(qDiv);
/* ========== MATCHING (Click-Click) ========== */
function showMatching(category) {
const container = document.getElementById('matching-section');
container.innerHTML = '';
const categoryData = data[category] || [];
const shuffled = shuffleArray([...categoryData]);
const pairs = shuffled.slice(0, 12).filter(row => row[0] && row[1]);
if (pairs.length === 0) return container.textContent = 'No data found';
const matchingContainer = document.createElement('div');
matchingContainer.className = 'matching-container';
container.appendChild(matchingContainer);
const leftCol = document.createElement('div');
leftCol.className = 'matching-box';
const rightCol = document.createElement('div');
rightCol.className = 'matching-box';
matchingContainer.appendChild(leftCol);
matchingContainer.appendChild(rightCol);
const leftWords = pairs.map(p => p[0]);
const rightWords = shuffleArray(pairs.map(p => p[1]));
let firstSelection = null;
const palette = ['#FFB3B3', '#FFD1A3', '#FFF3A3', '#C9F7B5', '#B7F0F6', '#C9C6FF', '#F7B3FF', '#DE85A6','#F0A326', '#E9FC6D', "#28992a", "#43a6e8" ];
function createBox(word, side) {
const div = document.createElement('div');
div.className = 'drag-item';
div.style.flex = '1 1 45%';
div.style.height = '50px';
div.style.display = 'flex';
div.style.alignItems = 'center';
div.style.justifyContent = 'center';
div.style.border = '2px solid #666';
div.style.cursor = 'pointer';
div.style.backgroundColor = '#eee';
div.onclick = () => handleClick(div);
function handleClick(box) {
box.style.border = '2px solid blue';
} else if (box.dataset.side !== firstSelection.dataset.side) {
const leftWord = firstSelection.dataset.side === 'left' ? firstSelection.dataset.word : box.dataset.word;
const rightWord = firstSelection.dataset.side === 'right' ? firstSelection.dataset.word : box.dataset.word;
const correctRight = pairs.find(p => p[0] === leftWord)?.[1];
if (rightWord === correctRight) {
const color = palette[colorIndex % palette.length];
[firstSelection, box].forEach(el => {
el.style.backgroundColor = color;
const pairChip = document.createElement('div');
pairChip.className = 'pair';
pairChip.style.backgroundColor = color;
pairChip.innerHTML = `<span>${leftWord}</span><span class="sep">↔</span><span>${rightWord}</span>`;
container.insertBefore(pairChip, matchingContainer);
[firstSelection, box].forEach(el => {
el.style.backgroundColor = 'lightcoral';
setTimeout(() => el.style.backgroundColor = '#eee', 500);
firstSelection.style.border = '';
leftWords.forEach(w => leftCol.appendChild(createBox(w, 'left')));
rightWords.forEach(w => rightCol.appendChild(createBox(w, 'right')));
/* ========== UPDATE CONTENT BASED ON DROPDOWN ========== */
function updateContent() {
const category = document.getElementById('category').value;
showFlashcards(category);
// Initialize with default category