-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (43 loc) · 1.63 KB
/
script.js
File metadata and controls
51 lines (43 loc) · 1.63 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
const exercises = [
"Jumping Jacks",
"Push-ups",
"Sit-ups",
"Squats",
"Lunges",
"Plank",
"Burpees",
"Mountain Climbers",
"High Knees",
"Butt Kicks"
];
let currentExerciseIndex = 0;
// Ensure DOM elements are fetched after the DOM is fully loaded
document.addEventListener("DOMContentLoaded", function() {
const exerciseDisplay = document.getElementById("exercise-display");
const nextButton = document.getElementById("next-button");
const restartButton = document.getElementById("restart-button");
// Display the first exercise on page load
exerciseDisplay.textContent = exercises[currentExerciseIndex];
// Event listener for the "Next" button
nextButton.addEventListener("click", () => {
currentExerciseIndex++;
if (currentExerciseIndex < exercises.length) {
// Show the next exercise
exerciseDisplay.textContent = exercises[currentExerciseIndex];
}
// When the last exercise is reached, hide the "Next" button and show the "Restart" button
if (currentExerciseIndex === exercises.length - 1) {
nextButton.style.display = "none";
restartButton.style.display = "block";
}
});
// Event listener for the "Restart" button
restartButton.addEventListener("click", () => {
// Reset to the first exercise
currentExerciseIndex = 0;
exerciseDisplay.textContent = exercises[currentExerciseIndex];
// Show the "Next" button again and hide the "Restart" button
nextButton.style.display = "block";
restartButton.style.display = "none";
});
});