let questions = null; const API_BASE = window.location.hostname === 'localhost' ? 'http://localhost:3001' : 'https://your-backend-domain.com'; const loadQuestions = async ( isSearch, categories, sourceScheme, questionCount ) => { if (questions === null) { try { questions = await (await fetch(`${API_BASE}/api/fizika`)).json(); } catch (error) { console.error('Failed to load questions from API, falling back to local file:', error); questions = await (await fetch("fizika.json")).json(); } } let currentQuestions = questions.slice(); if (isSearch) { currentQuestions = currentQuestions.filter((q) => q.source.match(sourceScheme) ); } else { shuffleArray(currentQuestions); currentQuestions = currentQuestions.filter((q) => categories.includes(q.type) ); } resultHtml = ""; currentQuestions = currentQuestions.slice(0, questionCount); currentQuestions.forEach( ({ id, source, description, a, b, c, d, correct, image }, i) => { resultHtml += `

${i + 1}.

${source}

${description}
${image ? `
` : ""}



${ d ? `
` : "" }
`; } ); resultHtml += currentQuestions.length === 0 ? '
Nem található a keresésnek megfelelő feladat!
' : ``; return resultHtml; }; 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]]; } }