-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
158 lines (136 loc) · 5.12 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
/*---------------------Slider-------------------------*/
const menuBtn = document.getElementById("menu-btn");
const navLinks = document.getElementById("nav-links");
const closeIcon = navLinks.querySelector("i.ri-close-line");
// Toggle the mobile menu visibility
menuBtn.addEventListener("click", () => {
navLinks.classList.add("open");
menuBtn.setAttribute("aria-expanded", "true"); // Accessibility
});
// Close the menu when the close icon is clicked
if (closeIcon) {
closeIcon.addEventListener("click", () => {
navLinks.classList.remove("open");
menuBtn.setAttribute("aria-expanded", "false");
});
}
/*---------------------Navigation Active Link & Smooth Scroll-------------------------*/
function handleNavigationClick(event) {
// Prevent the default behavior of the anchor tag
event.preventDefault();
// Remove the 'active' class from all navigation links
const links = document.querySelectorAll("nav ul li");
links.forEach((link) => link.classList.remove("active"));
// Add the 'active' class to the clicked link's parent li element
event.target.parentNode.classList.add("active");
// Smooth scroll to the target section
const targetId = event.target.getAttribute("href").substring(1);
const targetSection = document.getElementById(targetId);
if (targetSection) {
targetSection.scrollIntoView({ behavior: "smooth" });
}
// Close the menu after clicking on a link (for mobile)
navLinks.classList.remove("open");
menuBtn.setAttribute("aria-expanded", "false");
}
const navLinksItems = document.querySelectorAll("nav ul li a");
navLinksItems.forEach((link) => {
link.addEventListener("click", handleNavigationClick);
});
// Existing BMI Calculator Logic
bmiBtn.addEventListener("click", () => {
const height = parseInt(document.getElementById("height").value);
const weight = parseInt(document.getElementById("weight").value);
const result = document.getElementById("output");
let heightStatus = false,
weightStatus = false;
if (height === "" || isNaN(height) || height <= 0) {
document.getElementById("height_error").innerHTML =
"Please provide a valid height";
} else {
document.getElementById("height_error").innerHTML = "";
heightStatus = true;
}
if (weight === "" || isNaN(weight) || weight <= 0) {
document.getElementById("weight_error").innerHTML =
"Please provide a valid weight";
} else {
document.getElementById("weight_error").innerHTML = "";
weightStatus = true;
}
if (heightStatus && weightStatus) {
const bmi = (weight / ((height * height) / 10000)).toFixed(2);
if (bmi < 18.6) {
result.innerHTML = "Underweight: " + bmi;
} else if (bmi > 24.9) {
result.innerHTML = "Overweight: " + bmi;
} else {
result.innerHTML = "Normal: " + bmi;
}
} else {
alert("The form has errors");
result.innerHTML = "";
}
});
// Add Protein Intake Calculator Logic
document.getElementById("protein-btn").addEventListener("click", function () {
let weight = parseFloat(document.getElementById("protein-weight").value);
let goal = document.getElementById("protein-goal").value;
let proteinIntake;
// Protein intake values based on goals (in grams per kg)
if (goal === "maintenance") {
proteinIntake = weight * 1.2;
} else if (goal === "muscle-gain") {
proteinIntake = weight * 1.6;
} else if (goal === "fat-loss") {
proteinIntake = weight * 2.0;
}
document.getElementById(
"protein-output"
).innerHTML = `You need approximately ${proteinIntake.toFixed(
2
)} grams of protein per day.`;
});
// Add Macronutrient Calculator Logic
document.getElementById("macro-btn").addEventListener("click", function () {
let weight = parseFloat(document.getElementById("macro-weight").value);
let goal = document.getElementById("macro-goal").value;
let calories = parseFloat(document.getElementById("macro-calories").value);
let proteinRatio, carbRatio, fatRatio;
// Macro ratios based on fitness goals
if (goal === "maintenance") {
proteinRatio = 0.3;
carbRatio = 0.4;
fatRatio = 0.3;
} else if (goal === "bulking") {
proteinRatio = 0.25;
carbRatio = 0.5;
fatRatio = 0.25;
} else if (goal === "cutting") {
proteinRatio = 0.35;
carbRatio = 0.3;
fatRatio = 0.35;
}
// Calculate macros in grams
let proteinGrams = (calories * proteinRatio) / 4;
let carbGrams = (calories * carbRatio) / 4;
let fatGrams = (calories * fatRatio) / 9;
document.getElementById(
"macro-output"
).innerHTML = `Your daily macronutrient breakdown:
Protein: ${proteinGrams.toFixed(2)}g,
Carbs: ${carbGrams.toFixed(2)}g,
Fats: ${fatGrams.toFixed(2)}g.`;
});
// Send email logic
function sendEmail() {
Email.send({
Host: "smtp.gmail.com",
Username: "pallavi867709@gmail.com",
Password: "Pallavi@2005??",
To: "pallavi867709@gmail.com",
From: document.getElementById("email").value,
Subject: "This is the subject",
Body: "And this is the body",
}).then((message) => alert(message));
}