🐳 25/03 - 14:34 - Build a responsive interactive learning app called Vedic Maths Visual Coach using only:- HTML- CSS- vanilla JavaScriptDo not use React, Next.js, Vue, Angular, Tailwind, Bootstrap, o
4abae96 verified Download components/practice.js from onlyoneritz/deepsite-project-p0ofg: direct link, hf CLI and curl.
- Browser
- Download file 7.49 kB
-
https://huggingface.co/spaces/onlyoneritz/deepsite-project-p0ofg/resolve/main/components/practice.js
- Command line
-
hf download hf://spaces/onlyoneritz/deepsite-project-p0ofg/components/practice.js
-
curl -L -o practice.js https://huggingface.co/spaces/onlyoneritz/deepsite-project-p0ofg/resolve/main/components/practice.js
7.49 kB
| // components/practice.js | |
| // Interactive practice with hints and feedback | |
| let currentPractice = { | |
| concept: null, | |
| questions: [], | |
| currentIndex: 0, | |
| score: 0, | |
| mode: 'guided' // 'guided' or 'independent' | |
| }; | |
| window.renderPractice = function(conceptId) { | |
| const content = document.getElementById('content'); | |
| const concept = conceptId ? window.concepts.find(c => c.id === conceptId) : window.concepts[0]; | |
| if (!concept) { | |
| content.innerHTML = '<p>No practice available.</p>'; | |
| return; | |
| } | |
| currentPractice.concept = concept; | |
| currentPractice.questions = concept.practiceQuestions || []; | |
| currentPractice.currentIndex = 0; | |
| currentPractice.score = 0; | |
| content.innerHTML = ` | |
| <div class="practice-section section active" id="practice"> | |
| <div class="practice-header"> | |
| <h1>Practice: ${concept.title}</h1> | |
| <div class="mode-toggle"> | |
| <button class="mode-btn ${currentPractice.mode === 'guided' ? 'active' : ''}" | |
| onclick="setMode('guided')">Guided</button> | |
| <button class="mode-btn ${currentPractice.mode === 'independent' ? 'active' : ''}" | |
| onclick="setMode('independent')">Test Mode</button> | |
| </div> | |
| </div> | |
| <div class="practice-container"> | |
| <div class="progress-tracker"> | |
| ${currentPractice.questions.map((_, idx) => ` | |
| <div class="progress-dot ${idx === 0 ? 'active' : ''} ${idx < 0 ? 'completed' : ''}"></div> | |
| `).join('')} | |
| </div> | |
| <div class="question-card"> | |
| <div class="difficulty-badge ${currentPractice.questions[0]?.difficulty || 'easy'}"> | |
| ${currentPractice.questions[0]?.difficulty || 'easy'} | |
| </div> | |
| <h2 class="question-text">${currentPractice.questions[0]?.q || '23 × 54 = ?'}</h2> | |
| <div class="hint-ladder" id="hint-ladder"> | |
| ${currentPractice.mode === 'guided' ? ` | |
| <button class="hint-btn" onclick="showHint(1)">💡 Hint 1: Start with vertical multiplication</button> | |
| <button class="hint-btn hidden" id="hint-2" onclick="showHint(2)">💡 Hint 2: Crosswise addition</button> | |
| <button class="hint-btn hidden" id="hint-3" onclick="showHint(3)">💡 Hint 3: Final vertical</button> | |
| ` : '<p class="test-mode-msg">No hints in test mode! Do your best! 💪</p>'} | |
| </div> | |
| <div class="answer-section"> | |
| <input type="number" id="answer-input" class="answer-input" placeholder="Your answer..." | |
| onkeypress="if(event.key==='Enter') checkAnswer()"> | |
| <button class="btn btn-primary" onclick="checkAnswer()">Check Answer</button> | |
| </div> | |
| <div class="feedback-area hidden" id="feedback"> | |
| <div class="feedback-content"></div> | |
| <button class="btn btn-secondary" onclick="nextQuestion()">Next →</button> | |
| </div> | |
| </div> | |
| <div class="practice-stats"> | |
| <div class="stat-box"> | |
| <span>Question</span> | |
| <strong>1/${currentPractice.questions.length}</strong> | |
| </div> | |
| <div class="stat-box"> | |
| <span>Score</span> | |
| <strong id="score-display">0</strong> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| if (window.lucide) lucide.createIcons(); | |
| }; | |
| window.setMode = function(mode) { | |
| currentPractice.mode = mode; | |
| renderPractice(currentPractice.concept.id); | |
| }; | |
| window.showHint = function(level) { | |
| const hints = { | |
| 1: "Multiply the left digits vertically (tens place)", | |
| 2: "Cross multiply and add (tens×units + units×tens)", | |
| 3: "Multiply right digits vertically (units place) and add any carry" | |
| }; | |
| const btn = document.getElementById(`hint-${level}`); | |
| if (btn) { | |
| btn.textContent = hints[level]; | |
| btn.classList.remove('hidden'); | |
| btn.disabled = true; | |
| } | |
| // Show next hint button | |
| if (level < 3) { | |
| const nextBtn = document.getElementById(`hint-${level + 1}`); | |
| if (nextBtn) nextBtn.classList.remove('hidden'); | |
| } | |
| }; | |
| window.checkAnswer = function() { | |
| const input = document.getElementById('answer-input'); | |
| const feedback = document.getElementById('feedback'); | |
| const currentQ = currentPractice.questions[currentPractice.currentIndex]; | |
| const userAns = parseInt(input.value); | |
| if (isNaN(userAns)) return; | |
| const isCorrect = userAns === currentQ.a; | |
| feedback.classList.remove('hidden'); | |
| if (isCorrect) { | |
| currentPractice.score++; | |
| feedback.innerHTML = ` | |
| <div class="feedback-correct"> | |
| <i data-lucide="check-circle"></i> | |
| <div> | |
| <h3>Correct! 🎉</h3> | |
| <p>${currentQ.a} is right!</p> | |
| </div> | |
| </div> | |
| `; | |
| updateProgress(true); | |
| } else { | |
| feedback.innerHTML = ` | |
| <div class="feedback-incorrect"> | |
| <i data-lucide="x-circle"></i> | |
| <div> | |
| <h3>Not quite</h3> | |
| <p>The answer is ${currentQ.a}. Let's review the steps!</p> | |
| <button class="btn btn-text" onclick="navigate('learn')">Review Concept</button> | |
| </div> | |
| </div> | |
| `; | |
| } | |
| document.getElementById('score-display').textContent = currentPractice.score; | |
| if (window.lucide) lucide.createIcons(); | |
| }; | |
| window.nextQuestion = function() { | |
| currentPractice.currentIndex++; | |
| if (currentPractice.currentIndex >= currentPractice.questions.length) { | |
| showPracticeComplete(); | |
| } else { | |
| // Reload with next question | |
| const content = document.getElementById('content'); | |
| const q = currentPractice.questions[currentPractice.currentIndex]; | |
| // Update UI for next question | |
| document.querySelector('.question-text').textContent = q.q; | |
| document.querySelector('.difficulty-badge').className = `difficulty-badge ${q.difficulty}`; | |
| document.querySelector('.difficulty-badge').textContent = q.difficulty; | |
| document.getElementById('answer-input').value = ''; | |
| document.getElementById('feedback').classList.add('hidden'); | |
| // Update progress dots | |
| document.querySelectorAll('.progress-dot').forEach((dot, idx) => { | |
| dot.classList.toggle('active', idx === currentPractice.currentIndex); | |
| dot.classList.toggle('completed', idx < currentPractice.currentIndex); | |
| }); | |
| // Update stats | |
| document.querySelector('.stat-box strong').textContent = | |
| `${currentPractice.currentIndex + 1}/${currentPractice.questions.length}`; | |
| } | |
| }; | |
| function showPracticeComplete() { | |
| const content = document.querySelector('.practice-container'); | |
| content.innerHTML = ` | |
| <div class="completion-card"> | |
| <div class="completion-icon">🎊</div> | |
| <h2>Practice Complete!</h2> | |
| <p>You scored ${currentPractice.score}/${currentPractice.questions.length}</p> | |
| <div class="completion-actions"> | |
| <button class="btn btn-primary" onclick="navigate('learn')">Learn More</button> | |
| <button class="btn btn-secondary" onclick="navigate('revision')">Review</button> | |
| </div> | |
| </div> | |
| `; | |
| // Mark concept as completed if score is good | |
| if (currentPractice.score >= currentPractice.questions.length * 0.7) { | |
| if (!state.conceptsCompleted.includes(currentPractice.concept.id)) { | |
| state.conceptsCompleted.push(currentPractice.concept.id); | |
| } | |
| } | |
| } | |
| function updateProgress(success) { | |
| // Update global state | |
| state.lastActivity = Date.now(); | |
| if (success && state.weekProgress < 100) { | |
| state.weekProgress = Math.min(100, state.weekProgress + 10); | |
| } | |
| } |