Skip to content

Commit

Permalink
Merge pull request Pallavi1926#32 from pavitraag/main
Browse files Browse the repository at this point in the history
Added 2 calculators
  • Loading branch information
Pallavi1926 authored Oct 1, 2024
2 parents dae809d + ccd5b07 commit b4831f1
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 72 deletions.
48 changes: 47 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,52 @@ <h2 class="bmi__header">BMI CALCULATOR</h2>
</div>
</section>

<!-- Protein Intake Calculator -->
<section class="section__container protein__container">
<div class="wrapper">
<h2 class="protein__header">Protein Intake Calculator</h2>
<p>Enter your details to estimate your daily protein needs:</p>

<label for="protein-weight">Weight (kg):</label>
<input type="number" id="protein-weight" placeholder="Your weight in kg">

<label for="protein-goal">Fitness Goal:</label>
<select id="protein-goal">
<option value="maintenance">Maintenance</option>
<option value="muscle-gain">Muscle Gain</option>
<option value="fat-loss">Fat Loss</option>
</select>

<button class="btn" id="protein-btn">Calculate Protein Intake</button>
<p id="protein-output"></p>
</div>
</section>

<!-- Macronutrient Calculator -->
<section class="section__container macro__container">
<div class="wrapper">
<h2 class="macro__header">Macronutrient Calculator</h2>
<p>Enter your details to calculate your daily macronutrient needs:</p>

<label for="macro-weight">Weight (kg):</label>
<input type="number" id="macro-weight" placeholder="Your weight in kg">

<label for="macro-goal">Fitness Goal:</label>
<select id="macro-goal">
<option value="maintenance">Maintenance</option>
<option value="bulking">Bulking</option>
<option value="cutting">Cutting</option>
</select>

<label for="macro-calories">Daily Calories:</label>
<input type="number" id="macro-calories" placeholder="Your daily calorie intake">

<button class="btn" id="macro-btn">Calculate Macros</button>
<p id="macro-output"></p>
</div>
</section>


<footer class="footer" id="contact">
<div class="section__container footer__container">
<div class="footer__col">
Expand Down Expand Up @@ -445,4 +491,4 @@ <h4>NEWSLETTER</h4>
<script src="main.js"></script>
</body>

</html>
</html>
173 changes: 102 additions & 71 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Existing Menu Button and ScrollReveal Logic
const menuBtn = document.getElementById("menu-btn");
const navLinks = document.getElementById("nav-links");
const menuBtnIcon = menuBtn.querySelector("i");
Expand All @@ -6,108 +7,138 @@ const bmiBtn = document.getElementById("btn");
menuBtn.addEventListener("click", (e) => {
navLinks.classList.toggle("open");


const isOpen = navLinks.classList.contains("open");
menuBtnIcon.setAttribute("class", isOpen ? "ri-close-line" : "ri-menu-line");

});

navLinks.addEventListener('click', (e) => {
navLinks.classList.remove('open');
menuBtnIcon.setAttribute('class', 'ri-menu-line')

})
menuBtnIcon.setAttribute('class', 'ri-menu-line');
});

const scrollRevealOption = {
distance : '50px',
distance: '50px',
origin: 'bottom',
duration: 1000,
};

ScrollReveal().reveal(".header__content h1", {
...scrollRevealOption,
})
ScrollReveal().reveal(".header__content h2", {
...scrollRevealOption,
delay: 500,
})
ScrollReveal().reveal(".header__content p", {
...scrollRevealOption,
delay: 1000,
})
ScrollReveal().reveal(".header__content .header__btn", {
...scrollRevealOption,
delay: 1500,
})
ScrollReveal().reveal(".about__card", {
duration:1000,
interval: 500,
})
ScrollReveal().reveal(".trainer__card", {
...scrollRevealOption,
interval: 500,
})
ScrollReveal().reveal(".blog__card", {
...scrollRevealOption,
interval: 500,
})
ScrollReveal().reveal(".header__content h1", {...scrollRevealOption});
ScrollReveal().reveal(".header__content h2", {...scrollRevealOption, delay: 500});
ScrollReveal().reveal(".header__content p", {...scrollRevealOption, delay: 1000});
ScrollReveal().reveal(".header__content .header__btn", {...scrollRevealOption, delay: 1500});
ScrollReveal().reveal(".about__card", {duration: 1000, interval: 500});
ScrollReveal().reveal(".trainer__card", {...scrollRevealOption, interval: 500});
ScrollReveal().reveal(".blog__card", {...scrollRevealOption, interval: 500});

const swiper = new Swiper(".swiper", {
loop: true,

pagination: {
el: ".swiper-pagination",
el: ".swiper-pagination",
},
});
});

bmiBtn.addEventListener("click", () => {
// 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 height_status=false, weight_status=false;
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 = '';
height_status=true;
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){

if (weight === '' || isNaN(weight) || weight <= 0) {
document.getElementById('weight_error').innerHTML = 'Please provide a valid weight';
}else{
document.getElementById('weight_error').innerHTML = '';
weight_status=true;
}
} else {
document.getElementById('weight_error').innerHTML = '';
weightStatus = true;
}

if(height_status && weight_status){
const bmi = (weight/((height*height)/10000)).toFixed(2);
if (heightStatus && weightStatus) {
const bmi = (weight / ((height * height) / 10000)).toFixed(2);

if(bmi < 18.6){
result.innerHTML = 'Under weight : '+bmi;
}
else if(bmi > 24.9){
result.innerHTML = 'Over weight : '+bmi;
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 = '';
}
else{
result.innerHTML = 'Normal : '+bmi;
});

// 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;
}
}else{
alert('The form has errors');
result.innerHTML = '';

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.`;
});

function sendEmail(){
// Send email logic
function sendEmail() {
Email.send({
Host : "smtp.gmail.com",
Username : "[email protected]",
Password : "Pallavi@2005??",
To : '[email protected]',
From : document.getElementById("email").value,
Subject : "This is the subject",
Body : "And this is the body"
Host: "smtp.gmail.com",
Username: "[email protected]",
Password: "Pallavi@2005??",
To: '[email protected]',
From: document.getElementById("email").value,
Subject: "This is the subject",
Body: "And this is the body"
}).then(
message => alert(message)
);
}
}
96 changes: 96 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,102 @@ url("assets/banner-2.png");
}


.protein__header{
font-size: 1.2rem;
font-weight: 600;
color: var(--text-dark);
}

.protein__container span{
color: red;
}
.protein__container{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height:400px;
background: white;



}

.protein__container .wrapper{
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 1.5rem;
width: 100%;

background: white;
border-radius: 5px;
box-shadow: rgb(38, 57, 77) 0px 20px 30px -10px;
background-image: linear-gradient(
to right,
rgba(187, 180, 180, 0.8),
rgba(187, 180, 180, 0.8)
),
url("assets/banner-2.png");
}
.protein__container input{
outline: none;
}
.protein__container .btn{
color:#5b5757
}


.macro__header{
font-size: 1.2rem;
font-weight: 600;
color: var(--text-dark);
}

.macro__container span{
color: red;
}
.macro__container{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height:400px;
background: white;



}

.macro__container .wrapper{
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
gap: 1.5rem;
width: 100%;

background: white;
border-radius: 5px;
box-shadow: rgb(38, 57, 77) 0px 20px 30px -10px;
background-image: linear-gradient(
to right,
rgba(187, 180, 180, 0.8),
rgba(187, 180, 180, 0.8)
),
url("assets/banner-2.png");
}
.macro__container input{
outline: none;
}
.macro__container .btn{
color:#5b5757
}


.footer {
background-color: var(--text-dark);
}
Expand Down

0 comments on commit b4831f1

Please sign in to comment.