Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const moodSelector = document.querySelector('.mood-selector');
+ const recommendation = document.querySelector('.recommendation');
+ const songTitle = document.querySelector('.song-title');
+ const songArtist = document.querySelector('.song-artist');
+ const newSongBtn = document.querySelector('.new-song-btn');
+ const backBtn = document.querySelector('.back-btn');
+
+ // Sample song database
+ const songDatabase = {
+ joyful: [
+ { title: "Happy", artist: "Pharrell Williams" },
+ { title: "I Got You (I Feel Good)", artist: "James Brown" },
+ { title: "Walking on Sunshine", artist: "Katrina & The Waves" }
+ ],
+ nostalgic: [
+ { title: "Yesterday", artist: "The Beatles" },
+ { title: "Time After Time", artist: "Cyndi Lauper" },
+ { title: "Sweet Dreams", artist: "Eurythmics" }
+ ],
+ adventurous: [
+ { title: "Eye of the Tiger", artist: "Survivor" },
+ { title: "Born to Run", artist: "Bruce Springsteen" },
+ { title: "The Final Countdown", artist: "Europe" }
+ ],
+ mellow: [
+ { title: "Chasing Cars", artist: "Snow Patrol" },
+ { title: "Hallelujah", artist: "Jeff Buckley" },
+ { title: "The Sound of Silence", artist: "Simon & Garfunkel" }
+ ],
+ energetic: [
+ { title: "Can't Hold Us", artist: "Macklemore & Ryan Lewis" },
+ { title: "Uptown Funk", artist: "Mark Ronson ft. Bruno Mars" },
+ { title: "I Gotta Feeling", artist: "The Black Eyed Peas" }
+ ],
+ romantic: [
+ { title: "Perfect", artist: "Ed Sheeran" },
+ { title: "All of Me", artist: "John Legend" },
+ { title: "At Last", artist: "Etta James" }
+ ]
+ };
+
+ let currentMood = '';
+
+ function getRandomSong(mood) {
+ const songs = songDatabaseood];
+ return songs[Math.floor(Math.random() * songs.length)];
+ }
+
+ function showRecommendation(mood) {
+ const song = getRandomSong(mood);
+ songTitle.textContent = song.title;
+ songArtist.textContent = song.artist;
+ moodSelector.classList.add('hidden');
+ recommendation.classList.remove('hidden');
+ currentMood = mood;
+ }
+
+ // Event Listeners
+ document.querySelectorAll('.mood-btn').forEach(btn => {
+ btn.addEventListener('click', () => {
+ showRecommendation(btn.dataset.mood);
+ });
+ });
+
+ newSongBtn.addEventListener('click', () => {
+ showRecommendation(currentMood);
+ });
+
+ backBtn.addEventListener('click', () => {
+ moodSelector.classList.remove('hidden');
+ recommendation.classList.add('hidden');
+ });
+ });