-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp.js
More file actions
64 lines (58 loc) · 1.91 KB
/
app.js
File metadata and controls
64 lines (58 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const circleProgress = document.querySelector(".circle-progress");
const numberOfBreaths = document.querySelector(".breath-input");
const start = document.querySelector(".start");
const instructions = document.querySelector(".instructions");
const breathsText = document.querySelector(".breaths-text");
let breathsLeft = 3;
// Watching for selected breaths from user
numberOfBreaths.addEventListener("change", () => {
breathsLeft = numberOfBreaths.value;
breathsText.innerText = breathsLeft;
});
// Grow/Shrink Circle
const growCircle = () => {
circleProgress.classList.add("circle-grow");
setTimeout(() => {
circleProgress.classList.remove("circle-grow");
}, 8000);
};
// Breathing Instructions
const breathTextUpdate = () => {
breathsLeft--;
breathsText.innerText = breathsLeft;
instructions.innerText = "Breath in";
setTimeout(() => {
instructions.innerText = "Hold Breath";
setTimeout(() => {
instructions.innerText = "Exhale Breath Slowly";
}, 4000);
}, 4000);
};
// Breathing App Function
const breathingApp = () => {
const breathingAnimtaion = setInterval(() => {
if (breathsLeft === 0) {
clearInterval(breathingAnimtaion);
instructions.innerText = "Breathing session completed. Click 'Begin' to start another session!";
start.classList.remove("button-inactive");
breathsLeft = numberOfBreaths.value;
breathsText.innerText = breathsLeft;
return;
}
growCircle();
breathTextUpdate();
}, 12000);
};
// Start Breathing >>
start.addEventListener("click", () => {
start.classList.add("button-inactive");
instructions.innerText = "Get relaxed, and ready to begin breathing";
setTimeout(() => {
instructions.innerText = "Breathing is about to begin...";
setTimeout(() => {
breathingApp();
growCircle();
breathTextUpdate();
}, 2000);
}, 2000);
});