-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
83 lines (63 loc) · 2.39 KB
/
app.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//first i'm creating some variblaes
//and using document.querySelector to gather my classes from the index.html page
//and setting those classes as the variable value
const innerCircle = document.querySelector('.inner-circle');
const meditationMinutes = document.querySelector('.breath-selection');
const startMeditating = document.querySelector('.start');
const breathInstructions = document.querySelector('.breath-instructions');
const breathsLapsed = document.querySelector('.breaths-left');
let breathsLeft = 5;
//when the user makes their selection for meditation length of time
//the event will fire after it listens for the change event
//then a callback function is added for each time the
//selection changes
meditationMinutes.addEventListener('change', () => {
breathsLeft = meditationMinutes.value;
breathsLapsed.innerText = breathsLeft;
})
//having the circle grow/shrink depending on the time
const growCircle = () => {
innerCircle.classList.add("circle-grow")
//use arrow function
setTimeout(() => {
innerCircle.classList.remove("circle-grow");
}, 10000);
};
//event listener for start button
startMeditating.addEventListener('click', () => {
growCircle();
})
// //event listener for audio
// .startMeditating.addEventListener('click', () => {
// })
//breathing instructions
const breathInstructionsUpdate = () => {
breathsLeft--;
breathsLapsed.innerText = breathsLeft;
breathInstructions.innerText = "Slowly Breathe In"
setTimeout(() => {
breathInstructions.innerText = "Hold Breath";
setTimeout(() => {
breathInstructions.innerText = "Slowly Breathe Out"
}, 5000);
}, 5000);
}
//breathing timing intervals(repeat)
const breathIntervals = () => {
const animateBreathing = setInterval(() => {
if (breathsLeft === 0) {
clearInterval(animateBreathing);
breathInstructions.innerText="Your breathing session is complete! To begin another session, press the 'Start' button.";
breathsLeft= meditationMinutes.value;
breathsLapsed.innerText = breathsLeft;
return;
}
growCircle();
breathInstructionsUpdate();
}, 15000)
};
startMeditating.addEventListener("click", () => {
breathIntervals();
growCircle();
breathInstructionsUpdate();
});