`;
grid.appendChild(card);
});
}
function highlightVerb(sentence, verb) {
const regex = new RegExp(`\\b(${verb})\\b`, 'gi');
return sentence.replace(regex, `$1`);
}
function filterBy(cat) {
currentFilter = cat;
document.querySelectorAll('.cat-btn').forEach(b => b.classList.remove('btn-active'));
event.target.classList.add('btn-active');
updateList();
}
function updateList() {
const query = searchInput.value.toLowerCase().trim();
filteredVerbs = verbData.filter(v => {
const searchStr = `${v.v1} ${v.v2} ${v.v3} ${v.v1_bn}`.toLowerCase();
const matchesSearch = searchStr.includes(query);
const matchesCat = currentFilter === 'All' || v.cat === currentFilter;
return matchesSearch && matchesCat;
});
renderVerbs();
}
searchInput.addEventListener('input', updateList);
// Quiz Engine
let quizState = { active: false, questions: [], currIdx: 0, score: 0 };
function startQuiz() {
const pool = [...verbData].sort(() => Math.random() - 0.5);
quizState.questions = pool.slice(0, 10);
quizState.currIdx = 0; quizState.score = 0; quizState.active = true;
renderQuizQuestion();
document.getElementById('quiz-section').scrollIntoView({ behavior: 'smooth' });
}
function renderQuizQuestion() {
const q = quizState.questions[quizState.currIdx];
const targetType = Math.random() > 0.5 ? 'v2' : 'v3';
const correctAnswer = q[targetType];
let choices = [correctAnswer];
while(choices.length < 4) {
const randomV = verbData[Math.floor(Math.random() * verbData.length)];
const wrongAns = randomV[targetType];
if(!choices.includes(wrongAns)) choices.push(wrongAns);
}
choices.sort(() => Math.random() - 0.5);
const quizBox = document.getElementById('quiz-box');
quizBox.innerHTML = `
What is the ${targetType.toUpperCase()} form of
`;
}
function checkAnswer(btn, selected, correct) {
const allBtns = btn.parentElement.querySelectorAll('button');
allBtns.forEach(b => b.disabled = true);
if(selected === correct) { btn.classList.add('choice-correct'); quizState.score++; }
else { btn.classList.add('choice-wrong'); allBtns.forEach(b => { if(b.innerText.trim() === correct) b.classList.add('choice-correct'); }); }
setTimeout(() => { quizState.currIdx++; if(quizState.currIdx < 10) renderQuizQuestion(); else showQuizResults(); }, 1000);
}
function showQuizResults() {
const quizBox = document.getElementById('quiz-box');
quizBox.innerHTML = `
`;
}
function initPlayground() { try { renderVerbs(); } catch (e) { setTimeout(initPlayground, 500); } }
window.onload = initPlayground;
Question ${quizState.currIdx + 1}/10
স্কোর: ${quizState.score}
What is the ${targetType.toUpperCase()} form of
"${q.v1}" (${q.v1_bn})?
${choices.map(c => ``).join('')}
🏆
কুইজ শেষ!
আপনি ১০ এর মধ্যে ${quizState.score} পেয়েছেন।