Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const submitButton = document.getElementById('submitButton');
+ const dictateButton = document.getElementById('dictateButton');
+ const wordInput = document.getElementById('wordInput');
+ const wordListDiv = document.getElementById('wordList');
+ const resultSection = document.getElementById('resultSection');
+ const resultsDiv = document.getElementById('results');
+
+ let words = [];
+ let currentIndex = 0;
+
+ const sections = {
+ input: document.getElementById('inputSection'),
+ dictation: document.getElementById('dictationSection'),
+ result: document.getElementById('resultSection')
+ };
+
+ function showSection(sectionName) {
+ Object.keys(sections).forEach(key => {
+ sections[key].style.display = key === sectionName ? 'block' : 'none';
+ });
+ }
+
+ function speak(text) {
+ return new Promise(resolve => {
+ const utterance = new SpeechSynthesisUtterance(text);
+ utterance.onend = resolve;
+ speechSynthesis.speak(utterance);
+ });
+ }
+
+ submitButton.addEventListener('click', () => {
+ words = wordInput.value
+ .split('\n')
+ .map(word => word.trim())
+ .filter(word => word);
+
+ if (words.length === 0) {
+ alert('Please enter at least one word!');
+ return;
+ }
+
+ wordInput.value = '';
+ showSection('dictation');
+ updateCounter();
+ });
+
+ function updateCounter() {
+ wordListDiv.textContent = `Words remaining: ${words.length - currentIndex}`;
+ }
+
+ dictateButton.addEventListener('click', async () => {
+ if (currentIndex < words.length) {
+ dictateButton.disabled = true;
+ await speak(words[currentIndex]);
+ currentIndex++;
+ updateCounter();
+ dictateButton.disabled = false;
+
+ if (currentIndex >= words.length) {
+ showResults();
+ }
+ }
+ });
+
+ function showResults() {
+ showSection('result');
+ resultsDiv.innerHTML = words
+ .map((word, index) => `
${index + 1}. ${word}
`)
+ .join('');
+ }
+ });