Skip to content

Commit d041258

Browse files
authored
Create demo.js
1 parent 2c3d5aa commit d041258

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

js/demo.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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();

0 commit comments

Comments
 (0)