NexIMPERA
would // otherwise terminate this block and execute for every quiz taker. const QUIZ_DATA = {"quiz":{"id":"4","title":"Stock Market Cycles: Bull vs. Bear Markets","slug":"stock-market-cycles-bull-vs-bear","description":"Test your knowledge on market sentiment, technical indicators, and investment strategies during both rising (Bull) and falling (Bear) market cycles. Perfect for investors looking to understand market psychology.","cover_image":null,"category":"Stock Market","difficulty":"medium","time_limit":"10","passing_score":"70","max_attempts":"0","is_active":"1","approval_status":"approved","approved_by":null,"approved_at":null,"rejection_note":null,"is_featured":"0","show_answers":"1","randomize_questions":"0","created_by":"1","created_at":"2026-07-12 09:15:14","updated_at":"2026-07-14 12:35:11"},"questions":[{"id":"55","quiz_id":"4","question":"What percentage decline from a recent market peak is generally accepted by analysts as the official threshold for a \u0022Bear Market\u0022?","question_type":"single","explanation":"A drop of 20% or more from recent highs across a broad market index (like the Nifty 50 or S\u0026P 500) is the standard definition of a bear market.","points":"2","order_num":"1","created_at":"2026-07-12 09:15:14","is_deleted":"0","options":[{"id":"283","question_id":"55","option_text":"5%","is_correct":"0","order_num":"1","is_deleted":"0"},{"id":"284","question_id":"55","option_text":"10%","is_correct":"0","order_num":"2","is_deleted":"0"},{"id":"285","question_id":"55","option_text":"20%","is_correct":"1","order_num":"3","is_deleted":"0"},{"id":"286","question_id":"55","option_text":"35%","is_correct":"0","order_num":"4","is_deleted":"0"}]},{"id":"56","quiz_id":"4","question":"What is a \u0022Dead Cat Bounce\u0022 in stock market terminology?","question_type":"single","explanation":"A Dead Cat Bounce is a temporary, short-lived recovery of asset prices from a prolonged decline or bear market, followed by a continuation of the downward trend.","points":"2","order_num":"2","created_at":"2026-07-12 09:15:14","is_deleted":"0","options":[{"id":"287","question_id":"56","option_text":"A stock that remains completely flat with zero trading volume","is_correct":"0","order_num":"1","is_deleted":"0"},{"id":"288","question_id":"56","option_text":"A temporary, short-lived recovery in prices during a prolonged decline","is_correct":"1","order_num":"2","is_deleted":"0"},{"id":"289","question_id":"56","option_text":"A company that goes bankrupt and is delisted from the exchange","is_correct":"0","order_num":"3","is_deleted":"0"},{"id":"290","question_id":"56","option_text":"A sudden, massive surge in a stock price right before the market closes","is_correct":"0","order_num":"4","is_deleted":"0"}]},{"id":"57","quiz_id":"4","question":"During a severe Bear Market, what typically happens to the VIX (Volatility Index)?","question_type":"single","explanation":"The VIX is often referred to as the \u0022fear gauge.\u0022 During bear markets and market panics, volatility increases, causing the VIX to spike significantly.","points":"2","order_num":"3","created_at":"2026-07-12 09:15:14","is_deleted":"0","options":[{"id":"291","question_id":"57","option_text":"It drops to zero","is_correct":"0","order_num":"1","is_deleted":"0"},{"id":"292","question_id":"57","option_text":"It remains completely stable","is_correct":"0","order_num":"2","is_deleted":"0"},{"id":"293","question_id":"57","option_text":"It spikes significantly upward","is_correct":"1","order_num":"3","is_deleted":"0"},{"id":"294","question_id":"57","option_text":"It perfectly mirrors the exact price of the underlying index","is_correct":"0","order_num":"4","is_deleted":"0"}]},{"id":"58","quiz_id":"4","question":"Which of the following investment strategies is explicitly designed to profit from a falling stock price during a Bear Market?","question_type":"single","explanation":"Short selling involves borrowing shares and selling them at the current high price, with the intention of buying them back later at a lower price to return to the lender, keeping the difference as profit.","points":"2","order_num":"4","created_at":"2026-07-12 09:15:14","is_deleted":"0","options":[{"id":"295","question_id":"58","option_text":"Systematic Investment Planning (SIP)","is_correct":"0","order_num":"1","is_deleted":"0"},{"id":"296","question_id":"58","option_text":"Value Investing","is_correct":"0","order_num":"2","is_deleted":"0"},{"id":"297","question_id":"58","option_text":"Short Selling","is_correct":"1","order_num":"3","is_deleted":"0"},{"id":"298","question_id":"58","option_text":"Dividend Harvesting","is_correct":"0","order_num":"4","is_deleted":"0"}]},{"id":"59","quiz_id":"4","question":"What is a \u0022Bull Trap\u0022?","question_type":"single","explanation":"A Bull Trap is a false signal indicating that a declining trend in a stock has reversed and is heading upwards, tricking investors into buying before the price resumes its decline.","points":"2","order_num":"5","created_at":"2026-07-12 09:15:14","is_deleted":"0","options":[{"id":"299","question_id":"59","option_text":"A false signal that a declining stock is reversing and heading upward","is_correct":"1","order_num":"1","is_deleted":"0"},{"id":"300","question_id":"59","option_text":"A regulatory halt placed on a stock that is rising too fast","is_correct":"0","order_num":"2","is_deleted":"0"},{"id":"301","question_id":"59","option_text":"A strategy used by institutional investors to hide their large purchases","is_correct":"0","order_num":"3","is_deleted":"0"},{"id":"302","question_id":"59","option_text":"A physical location on the trading floor where aggressive buying happens","is_correct":"0","order_num":"4","is_deleted":"0"}]},{"id":"60","quiz_id":"4","question":"During a prolonged Bear Market, investors often rotate their capital into \u0022Defensive Stocks.\u0022 Which of the following is considered a defensive sector?","question_type":"single","explanation":"Consumer Staples (like food, basic hygiene products) are defensive because people continue to buy these essential goods regardless of the economic climate.","points":"2","order_num":"6","created_at":"2026-07-12 09:15:14","is_deleted":"0","options":[{"id":"303","question_id":"60","option_text":"High-growth Technology","is_correct":"0","order_num":"1","is_deleted":"0"},{"id":"304","question_id":"60","option_text":"Consumer Staples (FMCG)","is_correct":"1","order_num":"2","is_deleted":"0"},{"id":"305","question_id":"60","option_text":"Luxury Automobiles","is_correct":"0","order_num":"3","is_deleted":"0"},{"id":"306","question_id":"60","option_text":"Cryptocurrency Mining","is_correct":"0","order_num":"4","is_deleted":"0"}]},{"id":"61","quiz_id":"4","question":"Which animal is used to represent a market characterized by rising prices, strong economic growth, and high investor optimism?","question_type":"single","explanation":"The Bull represents a rising market. The metaphor allegedly comes from the way a bull attacks by thrusting its horns upward into the air.","points":"2","order_num":"7","created_at":"2026-07-12 09:15:14","is_deleted":"0","options":[{"id":"307","question_id":"61","option_text":"Bear","is_correct":"0","order_num":"1","is_deleted":"0"},{"id":"308","question_id":"61","option_text":"Hawk","is_correct":"0","order_num":"2","is_deleted":"0"},{"id":"309","question_id":"61","option_text":"Bull","is_correct":"1","order_num":"3","is_deleted":"0"},{"id":"310","question_id":"61","option_text":"Whale","is_correct":"0","order_num":"4","is_deleted":"0"}]},{"id":"62","quiz_id":"4","question":"What does the financial term \u0022Capitulation\u0022 mean at the bottom of a Bear Market?","question_type":"single","explanation":"Capitulation is the point of maximum panic where investors give up trying to recapture lost gains and sell their positions aggressively, often marking the absolute bottom of a bear market.","points":"2","order_num":"8","created_at":"2026-07-12 09:15:14","is_deleted":"0","options":[{"id":"311","question_id":"62","option_text":"When companies start paying out massive special dividends","is_correct":"0","order_num":"1","is_deleted":"0"},{"id":"312","question_id":"62","option_text":"The point where investors panic-sell their assets, giving up on any recovery","is_correct":"1","order_num":"2","is_deleted":"0"},{"id":"313","question_id":"62","option_text":"When central banks raise interest rates to their maximum limits","is_correct":"0","order_num":"3","is_deleted":"0"},{"id":"314","question_id":"62","option_text":"When a company aggressively buys back its own shares","is_correct":"0","order_num":"4","is_deleted":"0"}]},{"id":"63","quiz_id":"4","question":"Which economic phase is most closely associated with the beginning of a new Bull Market?","question_type":"single","explanation":"Bull markets typically begin during periods of economic recovery and expansion, often before the actual economic data shows clear improvement, as markets are forward-looking.","points":"2","order_num":"9","created_at":"2026-07-12 09:15:14","is_deleted":"0","options":[{"id":"315","question_id":"63","option_text":"Economic Recession","is_correct":"0","order_num":"1","is_deleted":"0"},{"id":"316","question_id":"63","option_text":"Economic Recovery and Expansion","is_correct":"1","order_num":"2","is_deleted":"0"},{"id":"317","question_id":"63","option_text":"Economic Depression","is_correct":"0","order_num":"3","is_deleted":"0"},{"id":"318","question_id":"63","option_text":"Economic Stagflation","is_correct":"0","order_num":"4","is_deleted":"0"}]},{"id":"64","quiz_id":"4","question":"Which of the following sectors is highly cyclical and typically outperforms during a strong Bull Market?","question_type":"single","explanation":"Consumer Discretionary (luxury goods, travel, high-end autos) performs best in a bull market because consumers have higher disposable income and confidence.","points":"2","order_num":"10","created_at":"2026-07-12 09:15:14","is_deleted":"0","options":[{"id":"319","question_id":"64","option_text":"Utilities and Water Management","is_correct":"0","order_num":"1","is_deleted":"0"},{"id":"320","question_id":"64","option_text":"Government Treasury Bonds","is_correct":"0","order_num":"2","is_deleted":"0"},{"id":"321","question_id":"64","option_text":"Consumer Discretionary","is_correct":"1","order_num":"3","is_deleted":"0"},{"id":"322","question_id":"64","option_text":"Gold and Precious Metals","is_correct":"0","order_num":"4","is_deleted":"0"}]}]}; const SITE_URL = 'https://neximpera.com'; const USER_ID = null; // Unlimited label generator: A,B...Z,AA,AB...ZZ,AAA... function indexToLabel(i) { const alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; if (i < 26) return alpha[i]; let label = ''; i++; while (i > 0) { i--; label = alpha[i % 26] + label; i = Math.floor(i / 26); } return label; } let currentQ = 0; let answers = {}; // { question_id: { selected: [optId, ...] } } let attemptId = null; let startTime = null; let timerInterval = null; let userInfo = {}; document.getElementById('userInfoForm').addEventListener('submit', async (e) => { e.preventDefault(); const form = e.target; userInfo = { name: form.name.value.trim(), email: form.email.value.trim(), phone: form.phone.value.trim(), city: form.city.value.trim(), occupation: form.occupation.value.trim(), experience: form.experience.value, quiz_id: QUIZ_DATA.quiz.id, user_id: USER_ID }; const btn = document.getElementById('startQuizBtn'); btn.disabled = true; btn.textContent = 'Starting…'; try { const res = await fetch(SITE_URL + '/api/quiz.php?action=start', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify(userInfo) }); const data = await res.json(); if (data.success) { attemptId = data.attempt_id; startTime = Date.now(); document.getElementById('userInfoModal').classList.remove('active'); document.getElementById('quizInterface').style.display = 'block'; renderQuestion(); if (QUIZ_DATA.quiz.time_limit > 0) startTimer(QUIZ_DATA.quiz.time_limit * 60); } else { showToast(data.error || 'Error starting quiz', 'error'); btn.disabled = false; btn.textContent = ' Start Quiz'; } } catch(err) { showToast('Network error. Please try again.', 'error'); btn.disabled = false; btn.textContent = ' Start Quiz'; } }); function renderQuestion() { const q = QUIZ_DATA.questions[currentQ]; const total = QUIZ_DATA.questions.length; document.getElementById('questionNum').textContent = `Question ${currentQ + 1} of ${total}`; document.getElementById('questionCounter').textContent = `Q${currentQ+1}/${total}`; document.getElementById('questionText').textContent = q.question; document.getElementById('progressFill').style.width = (currentQ / total * 100) + '%'; // Type hint const hint = document.getElementById('questionTypeHint'); if (q.question_type === 'multiple') { hint.textContent = ' Select all correct answers'; hint.style.display = 'block'; } else { hint.style.display = 'none'; } const list = document.getElementById('optionsList'); list.innerHTML = ''; q.options.forEach((opt, i) => { const div = document.createElement('div'); div.className = 'quiz-option'; div.dataset.id = opt.id; const label = indexToLabel(i); // A, B, C ... Z, AA, AB ... div.innerHTML = `
${escapeHtml(label)}
${escapeHtml(opt.option_text)}
`; // Restore prior selection if (answers[q.id] && answers[q.id].selected.includes(opt.id)) { div.classList.add('selected'); } div.addEventListener('click', () => selectOption(div, opt.id, q)); list.appendChild(div); }); const expBox = document.getElementById('explanation'); if (answers[q.id]) { showExplanation(q); markOptions(q); } else { expBox.style.display = 'none'; } // Dot nav const dots = document.getElementById('dotNav'); dots.innerHTML = ''; const maxDots = Math.min(total, 20); for (let i = 0; i < maxDots; i++) { const d = document.createElement('div'); d.style.cssText = `width:8px;height:8px;border-radius:50%;transition:all 0.25s;cursor:pointer;background:${i===currentQ?'var(--gold)':answers[QUIZ_DATA.questions[i].id]?'var(--teal)':'var(--border-subtle)'}`; d.title = `Question ${i+1}`; const idx = i; d.onclick = () => { currentQ = idx; renderQuestion(); }; dots.appendChild(d); } if (total > 20) { const more = document.createElement('span'); more.style.cssText = 'font-size:11px;color:var(--text-muted);padding:0 4px'; more.textContent = `+${total - 20} more`; dots.appendChild(more); } document.getElementById('prevBtn').style.visibility = currentQ > 0 ? 'visible' : 'hidden'; const nextBtn = document.getElementById('nextBtn'); nextBtn.textContent = currentQ === total - 1 ? 'Submit Quiz ✓' : 'Next →'; } function selectOption(div, optId, q) { if (answers[q.id]) return; // already answered if (q.question_type === 'multiple') { // Toggle for multiple choice if (!answers[q.id]) answers[q.id] = { selected: [] }; const idx = answers[q.id].selected.indexOf(optId); if (idx === -1) { answers[q.id].selected.push(optId); div.classList.add('selected'); } else { answers[q.id].selected.splice(idx, 1); div.classList.remove('selected'); } // For multiple: don't lock until Next is clicked return; } // Single / true_false: lock immediately document.querySelectorAll('.quiz-option').forEach(o => o.classList.remove('selected')); div.classList.add('selected'); answers[q.id] = { selected: [optId] }; showExplanation(q); markOptions(q); } function markOptions(q) { const ans = answers[q.id]; if (!ans) return; const correctIds = q.options.filter(o => parseInt(o.is_correct)).map(o => o.id); document.querySelectorAll('.quiz-option').forEach(opt => { const id = parseInt(opt.dataset.id); const isSelected = ans.selected.includes(id); const isCorrect = correctIds.includes(id); opt.classList.remove('selected'); if (isSelected && isCorrect) opt.classList.add('correct'); else if (isSelected) opt.classList.add('wrong'); else if (isCorrect) opt.classList.add('correct'); }); } function showExplanation(q) { if (q.explanation && QUIZ_DATA.quiz.show_answers === '1') { document.getElementById('explanationText').textContent = q.explanation; document.getElementById('explanation').style.display = 'block'; } } function prevQuestion() { if (currentQ > 0) { currentQ--; renderQuestion(); } } async function nextQuestion() { const q = QUIZ_DATA.questions[currentQ]; const isMultiple = q.question_type === 'multiple'; // For multiple-choice, lock & mark on Next if (isMultiple && !answers[q.id]) { const selected = [...document.querySelectorAll('.quiz-option.selected')].map(d => parseInt(d.dataset.id)); if (!selected.length) { showToast('Select at least one answer', 'info'); return; } answers[q.id] = { selected }; markOptions(q); showExplanation(q); return; // let them see feedback before moving } if (!answers[q.id] && !isMultiple) { showToast('Please select an answer', 'info'); return; } if (currentQ < QUIZ_DATA.questions.length - 1) { currentQ++; renderQuestion(); } else { await submitQuiz(); } } async function submitQuiz() { if (timerInterval) clearInterval(timerInterval); const timeTaken = Math.round((Date.now() - startTime) / 1000); try { const res = await fetch(SITE_URL + '/api/quiz.php?action=submit', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ attempt_id: attemptId, answers, time_taken: timeTaken }) }); const data = await res.json(); if (data.success) showResults(data, timeTaken); else showToast(data.error || 'Submit failed', 'error'); } catch(e) { showToast('Error submitting. Try again.', 'error'); } } function showResults(data, timeTaken) { document.getElementById('quizInterface').style.display = 'none'; document.getElementById('resultsPanel').style.display = 'block'; const score = Math.round(data.score); const passed = score >= parseInt(QUIZ_DATA.quiz.passing_score); // innerHTML, not textContent - these are SVG fragments, and textContent // would render the markup as visible source. document.getElementById('resultEmoji').innerHTML = score >= 80 ? "<\/svg>" : score >= 60 ? "<\/svg>" : "<\/svg>"; document.getElementById('scoreDisplay').textContent = score + '%'; document.getElementById('scoreCircle').style.setProperty('--score-pct', score + '%'); document.getElementById('resultTitle').textContent = passed ? 'Congratulations! You Passed!' : 'Keep Practicing!'; document.getElementById('resultDesc').textContent = passed ? `You scored ${score}% — excellent financial knowledge!` : `You scored ${score}%. Passing score is ${QUIZ_DATA.quiz.passing_score}%. Review and try again!`; document.getElementById('correctCount').textContent = data.correct; document.getElementById('wrongCount').textContent = data.wrong; const m = Math.floor(timeTaken/60), s = timeTaken%60; document.getElementById('timeTaken').textContent = m > 0 ? `${m}m ${s}s` : `${s}s`; document.getElementById('progressFill').style.width = '100%'; if (QUIZ_DATA.quiz.show_answers === '1') { const review = document.getElementById('answerReview'); review.innerHTML = '

Answer Review

'; QUIZ_DATA.questions.forEach((q, i) => { const ans = answers[q.id]; const selectedIds = ans?.selected || []; const correctOpts = q.options.filter(o => parseInt(o.is_correct)); const isCorrect = correctOpts.length && correctOpts.every(co => selectedIds.includes(co.id)) && selectedIds.every(sid => correctOpts.some(co => co.id === sid)); review.innerHTML += `
${isCorrect?'':''}
Q${i+1}: ${escapeHtml(q.question)}
${q.options.map((opt, oi) => { const isSel = selectedIds.includes(opt.id); const isC = parseInt(opt.is_correct); let s = `background:${isSel&&isC?'rgba(45,212,191,0.08)':isSel?'rgba(251,113,133,0.08)':isC?'rgba(45,212,191,0.04)':'transparent'};border:1px solid ${isSel&&isC?'rgba(45,212,191,0.3)':isSel?'rgba(251,113,133,0.3)':isC?'rgba(45,212,191,0.2)':'var(--border-subtle)'};`; return `
${indexToLabel(oi)} ${escapeHtml(opt.option_text)} ${isSel ? `${isC?'✓ Correct':'✗ Wrong'}` : ''} ${!isSel && isC ? `Correct Answer` : ''}
`; }).join('')} ${q.explanation ? `
${escapeHtml(q.explanation)}
` : ''}
`; }); } } function startTimer(seconds) { let rem = seconds; const el = document.getElementById('quizTimer'); timerInterval = setInterval(() => { rem--; const m = Math.floor(rem/60).toString().padStart(2,'0'); const s = (rem%60).toString().padStart(2,'0'); el.textContent = `${m}:${s}`; if (rem <= 60) el.style.color = 'var(--rose)'; if (rem <= 0) { clearInterval(timerInterval); submitQuiz(); } }, 1000); } function escapeHtml(s) { return String(s).replace(/&/g,'&').replace(//g,'>').replace(/"/g,'"'); }