-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
194 lines (164 loc) · 5.21 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
let header = document.querySelector(".header");
let closBtn = document.querySelector(`.nav-close`);
let openBtn = document.querySelector(`.nav-open`);
let navBtn = document.querySelectorAll(".main-nav ul li");
navBtn.forEach((e) => {
e.onclick = function () {
header.classList.toggle("open");
};
});
openBtn.addEventListener("click", (e) => {
header.classList.add("open");
});
closBtn.addEventListener("click", (e) => {
header.classList.remove("open");
});
//BMI CALCULATOR
function calculateBmi(e) {
let weightInput = document.querySelector(".weight-input");
let heightInput = document.querySelector(".height-input");
let bmiResult = document.querySelector(".result-bmi");
let weightResult = document.querySelector(".result-weight");
// Check if the elements are present before accessing their values
if (weightInput && heightInput) {
let weight = parseFloat(weightInput.value);
let height = parseFloat(heightInput.value);
if (isNaN(weight) || isNaN(height) || height <= 0) {
bmiResult.textContent = '';
weightResult.textContent = 'Please enter valid weight and height values.';
return;
}
let bmi = (weight / (height * height)) * 10000; // Adjust for height in cm
bmiResult.innerHTML = bmi.toFixed(2);
if (bmi <= 24.9) {
weightResult.innerHTML = 'underweight';
} else if (bmi >= 25 && bmi <= 29.9) {
weightResult.innerHTML = 'healthy weight';
} else {
weightResult.innerHTML = 'overweight';
}
}
}
// *********************************************************************Scedule
//hena darna object dyalna howa lwl bach ikon intiliase to others
const schedules = {
Monday: {
className1: "BasketBall",
time1: "10:30am-12:00am",
trainer1: "Youssef Smith",
},
Tuesday: {
className1: "Yoga",
time1: "10:30am-11:30am",
trainer1: "Isabella Thomas",
className2: "Yoga",
time2: "10:00am-11:00am",
trainer2: "Ethan Brown",
className3: "Crossfit",
time3: "4:00am-5:00am",
trainer3: "Sophia Martinez",
},
Wednesday: {
className1: "fitness",
time1: "11:30am-12:30am",
trainer1: "Sophia Martinez",
},
Thursday: {
className1: "Cross fit",
time1: "8:30am-9:30am",
trainer1: "William Anderson",
},
Friday: {
className1: "FootBall",
time1: "9:30am-10:30am",
trainer1: "Ethan Brown",
},
Saturday: {
className1: "fitness",
time1: "11:30am-12:30am",
trainer1: "Emily Smith",
},
Sunday: {
className1: "Running",
time1: "10:30am-12:00am",
trainer1: "James Johnson",
},
};
// hena darna declare list and initialize
let list = document.querySelectorAll(".days li");
showData();
list.forEach((dayElement) => {
dayElement.onclick = function (e) {
// Add "active" class to the clicked element
e.currentTarget.classList.add("active");
// Remove "active" class from all other elements
list.forEach((li) => {
if (li !== e.currentTarget) {
li.classList.remove("active");
}
});
// Store a unique identifier (for example, the day name) in localStorage
localStorage.setItem("selectedDay", e.currentTarget.dataset.day); // current target ki locala as string
// Show schedule for the clicked day
showSchedule(e.currentTarget.dataset.day);
};
});
// ... (Previous code remains unchanged)
function showSchedule(day) {
const scheduleContent = document.getElementById("scheduleContent");
// Check if the scheduleContent element is found
if (scheduleContent) {
scheduleContent.innerHTML = ""; // Clear previous content
const schedule = schedules[day];
if (schedule) {
// Iterate over each session and create HTML elements
for (let i = 1; i <= 3; i++) {
const className = schedule[`className${i}`];
const time = schedule[`time${i}`];
const trainer = schedule[`trainer${i}`];
if (className && time && trainer) {
scheduleContent.innerHTML += `
<ul class="content-table">
<li>
<p class="text">Class Name</p>
<p class="content">${className}</p>
</li>
<li>
<p class="text">Time</p>
<p class="content">${time}</p>
</li>
<li>
<p class="text">Trainer</p>
<p class="content">${trainer}</p>
</li>
<li>
<button class="button">Join Now</button>
</li>
</ul>`;
}
}
}
} else {
console.error("Element with ID 'scheduleContent' not found.");
}
}
// ... (Remaining code remains unchanged)
function showData() {
let storedDay = localStorage.getItem("selectedDay");
// If "selectedDay" is found, apply the "active" class to the corresponding element
if (storedDay) {
list.forEach((dayElement) => {
if (dayElement.dataset.day === storedDay) {
// ila kant sotredday ki sawi datsetday dir lih class active
dayElement.classList.add("active");
} else {
dayElement.classList.remove("active");
}
});
if (storedDay) {
showSchedule(storedDay); // il kan l9ima lmokhazana fi local baynha bnfs function showSchedule
}
} else {
showSchedule("Monday");
}
}