File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ let stressLevel = 30 ;
2+ let simulationInterval ;
3+ const maxStress = 100 ;
4+ const minStress = 0 ;
5+
6+ function updateStressDisplay ( ) {
7+ document . getElementById ( 'stress-progress' ) . style . width = stressLevel + '%' ;
8+ document . getElementById ( 'stress-value' ) . textContent = Math . round ( stressLevel ) + '%' ;
9+ document . getElementById ( 'heart-rate' ) . textContent = Math . floor ( 80 + ( stressLevel * 0.4 ) ) ;
10+ document . getElementById ( 'oxygen' ) . textContent = Math . max ( 85 , 100 - Math . floor ( stressLevel * 0.15 ) ) ;
11+ }
12+
13+ function startScenario ( ) {
14+ if ( ! simulationInterval ) {
15+ simulationInterval = setInterval ( ( ) => {
16+ if ( stressLevel < maxStress ) {
17+ stressLevel += Math . random ( ) * 1.5 ;
18+ updateStressDisplay ( ) ;
19+ }
20+ } , 2000 ) ;
21+ }
22+ }
23+
24+ function resetScenario ( ) {
25+ clearInterval ( simulationInterval ) ;
26+ simulationInterval = null ;
27+ stressLevel = 30 ;
28+ updateStressDisplay ( ) ;
29+ }
30+
31+ function applyBreathing ( ) {
32+ if ( stressLevel > 20 ) {
33+ stressLevel = Math . max ( minStress , stressLevel - 20 ) ;
34+ updateStressDisplay ( ) ;
35+ }
36+ }
37+
38+ function findSolution ( ) {
39+ if ( stressLevel > 10 ) {
40+ stressLevel = Math . max ( minStress , stressLevel - 10 ) ;
41+ updateStressDisplay ( ) ;
42+ }
43+ }
44+
45+ // Initialize
46+ updateStressDisplay ( ) ;
You can’t perform that action at this time.
0 commit comments