1+ document . addEventListener ( "DOMContentLoaded" , ( ) => {
2+ const moodOptions = [ 'very sad' , 'sad' , 'neutral' , 'happy' , 'very happy' ] ;
3+ const wellnessTips = [
4+ "Take a few deep breaths to center yourself." ,
5+ "Try to get at least 7-8 hours of sleep tonight." ,
6+ "Take a short walk to clear your mind." ,
7+ "Reach out to a friend or family member for support." ,
8+ "Practice gratitude by listing three things you're thankful for."
9+ ] ;
10+
11+ // References to DOM elements
12+ const moodOptionsContainer = document . getElementById ( "mood-options" ) ;
13+ const stressSlider = document . getElementById ( "stress-slider" ) ;
14+ const stressValueDisplay = document . getElementById ( "stress-value" ) ;
15+ const wellnessTipDisplay = document . getElementById ( "wellness-tip" ) ;
16+ const saveEntryButton = document . getElementById ( "save-entry" ) ;
17+
18+ // Initialize default state
19+ let selectedMood = 'neutral' ;
20+ let stressLevel = 5 ;
21+
22+ // Populate mood options
23+ moodOptions . forEach ( option => {
24+ const wrapper = document . createElement ( "div" ) ;
25+ wrapper . style . marginBottom = "10px" ;
26+
27+ const radioButton = document . createElement ( "input" ) ;
28+ radioButton . type = "radio" ;
29+ radioButton . id = option ;
30+ radioButton . name = "mood" ;
31+ radioButton . value = option ;
32+ if ( option === selectedMood ) radioButton . checked = true ;
33+ radioButton . addEventListener ( "change" , ( ) => {
34+ selectedMood = option ;
35+ console . log ( `Mood selected: ${ selectedMood } ` ) ;
36+ } ) ;
37+
38+ const label = document . createElement ( "label" ) ;
39+ label . htmlFor = option ;
40+ label . textContent = option . charAt ( 0 ) . toUpperCase ( ) + option . slice ( 1 ) ;
41+
42+ wrapper . appendChild ( radioButton ) ;
43+ wrapper . appendChild ( label ) ;
44+ moodOptionsContainer . appendChild ( wrapper ) ;
45+ } ) ;
46+
47+ // Handle stress slider change
48+ stressSlider . addEventListener ( "input" , ( event ) => {
49+ stressLevel = event . target . value ;
50+ stressValueDisplay . textContent = stressLevel ;
51+ console . log ( `Stress level: ${ stressLevel } ` ) ;
52+ } ) ;
53+
54+ // Generate a random wellness tip
55+ const generateWellnessTip = ( ) => {
56+ const randomTip = wellnessTips [ Math . floor ( Math . random ( ) * wellnessTips . length ) ] ;
57+ wellnessTipDisplay . textContent = randomTip ;
58+ console . log ( `Wellness Tip: ${ randomTip } ` ) ;
59+ } ;
60+
61+ // Add event listener to save entry
62+ saveEntryButton . addEventListener ( "click" , ( ) => {
63+ console . log ( "Saving Entry..." ) ;
64+ console . log ( `Mood: ${ selectedMood } , Stress Level: ${ stressLevel } ` ) ;
65+ generateWellnessTip ( ) ;
66+ alert ( "Your entry has been saved!" ) ;
67+ } ) ;
68+
69+ // Display an initial wellness tip
70+ generateWellnessTip ( ) ;
71+ } ) ;
72+
0 commit comments