-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
151 lines (138 loc) · 3.47 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const exercises = [
{
name: "pushups",
sets: 1,
reps: 10,
options: [
{ type: "normal" },
{ type: "wide" },
{ type: "close" },
{ type: "diamond" },
],
},
{
name: "sprints",
sets: 5,
reps: 1,
options: [
{ distance: "10m", reps: 2 },
{ distance: "20m" }
],
},
{
name: "lunges",
sets: 1,
reps: 10,
},
{
name: "squats",
sets: 1,
reps: 10,
},
{
name: "jumps",
sets: 1,
reps: 10,
options: [
{ type: "knees to chest" },
{ type: "box jump" },
],
},
{
name: "burpees",
sets: 1,
reps: 7,
},
{
name: "kettlebell swings",
sets: 1,
reps: 14,
options: [
{ type: "normal" },
{ type: "one-handed" },
],
},
{
name: "kettlebell presses",
sets: 2,
reps: 10,
},
{
name: "kettlebell holds",
sets: 2,
reps: 1,
options: [
{ duration: "20s", weight: "light" },
{ duration: "10s", weight: "heavy" },
],
},
{
name: "kettlebell snatches",
sets: 2,
reps: 10,
options: [
{ weight: "light" },
{ weight: "heavy", reps: 5 },
],
},
]
const newExerciseButton = document.querySelector(`[data-push="changeExercise"]`)
// const addExerciseButton = document.querySelector(`[data-push="addExercise"]`)
// const addExerciseField = document.querySelector(`[data-value="addExercise"]`)
newExerciseButton.addEventListener("click", pickExercise)
function pickExercise() {
// Find the current exercise index in the array
// const currentExerciseName = exercisePrintEls.innerText.toLowerCase() || null
// const newExercises = exercises.filter((excercise) => excercise.name.toLowerCase() !== currentExerciseName)
// const newExercise = newExercises[randomNumber(newExercises.length)].name
const printElGroups = document.querySelectorAll(`[data-group]`)
printElGroups.forEach((group) => {
const exercisePrintEls = group.querySelectorAll(`[data-exercise]`)
let selectedExercise = randomNumber(exercises.length)
exercisePrintEls.forEach((el) => {
let dataValue = el.dataset.exercise
if (dataValue === "options") {
let exerciseOptions
exerciseOptions = exercises[selectedExercise][dataValue] || Array.isArray(exerciseOptions) // exerciseOptions is either an array of objects or false
// If exerciseOptions is not false, then select a random object from the array, otherwise print N/A
let optionsToPrint
if (exerciseOptions === false) {
optionsToPrint = "N/A"
}
else {
const selectedExerciseOption = exerciseOptions[randomNumber(exerciseOptions.length)]
optionsToPrint = JSON.stringify(selectedExerciseOption)
}
el.innerText = optionsToPrint
// check if the array contains reps
// if (options.indexOf("reps") > -1) { // TODO: doesn't work because we need to look inside the object to see if it has reps
// el.innerText = `We have reps`
// }
// Pick a random option from the array
// Iterate though the object and print each value
// }
// else {
// // print all options
// el.innerText = `N/A`
// }
}
else {
el.innerText = exercises[selectedExercise][dataValue]
}
})
})
}
function randomNumber(maxNum) {
return Math.floor(Math.random() * maxNum)
}
// addExerciseButton.addEventListener("click", (ev) => addExercise(ev))
/* function addExercise(ev) {
ev.preventDefault()
const newExercise = addExerciseField.value.toLowerCase()
if (exercises.indexOf(newExercise) === -1) {
exercises.push(newExercise)
}
addExerciseField.value = ""
}
*/
// const randomNumber = (maxNum) => Math.floor(Math.random() * maxNum)