Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const ageButtons = document.querySelectorAll('.age-buttons button');
+ const storyPromptSection = document.getElementById('story-prompt');
+ const storyResultSection = document.getElementById('story-result');
+ const generateStoryButton = document.getElementById('generate-story');
+ const listenStoryButton = document.getElementById('listen-story');
+ const newStoryButton = document.getElementById('new-story');
+ const promptInput = document.getElementById('prompt-input');
+ const storyContent = document.getElementById('story-content');
+ const storyIllustration = document.getElementById('story-illustration');
+
+ ageButtons.forEach(button => {
+ button.addEventListener('click', function() {
+ storyPromptSection.classList.remove('hidden');
+ storyResultSection.classList.add('hidden');
+ });
+ });
+
+ generateStoryButton.addEventListener('click', function() {
+ const prompt = promptInput.value.trim();
+ if (prompt) {
+ generateStory(prompt);
+ }
+ });
+
+ listenStoryButton.addEventListener('click', function() {
+ const text = storyContent.innerText;
+ if ('speechSynthesis' in window) {
+ const utterance = new SpeechSynthesisUtterance(text);
+ speechSynthesis.speak(utterance);
+ }
+ });
+
+ newStoryButton.addEventListener('click', function() {
+ storyPromptSection.classList.remove('hidden');
+ storyResultSection.classList.add('hidden');
+ promptInput.value = '';
+ });
+
+ function generateStory(prompt) {
+ // Simple story generation logic
+ const story = `Once upon a time, there was a ${prompt}. They went on an adventure and discovered something magical. The end.`;
+ storyContent.innerText = story;
+ storyIllustration.innerHTML = '
'; // Placeholder for illustration
+ storyPromptSection.classList.add('hidden');
+ storyResultSection.classList.remove('hidden');
+ }
+ });