Introduction
In today's world, staying fit and healthy has become a priority for many individuals. With the rise of fitness apps and online health resources, personalized workout plans are more accessible than ever. But what if you could create a simple yet effective fitness tracker that calculates your Body Mass Index (BMI) and suggests workout routines based on your activity level, age, and other parameters? In this article, we'll walk through building a fitness tracker web application using HTML, CSS, and JavaScript.
What You’ll Need?
Before diving into the code, let's review the basic technologies we'll be using.
- HTML: To structure the page and collect user input (age, weight, height, gender, and activity level).
- CSS: To style the page and make it visually appealing.
- JavaScript: To handle user input, calculate BMI and daily caloric needs, and suggest workouts based on the data.
Let’s dive into the step-by-step process of building our Fitness Tracker web application, starting with the HTML structure and followed by styling with CSS and adding functionality using JavaScript.
Step 1. HTML Structure
The HTML layout is simple yet effective. The user is prompted to enter their age, weight, height, gender, and activity level, which are essential to calculate personalized workout recommendations.
Here's the HTML structure for gathering user input.
Step 2. CSS Styling
The CSS ensures that the app looks modern and user-friendly. A gradient background adds a touch of aesthetic appeal, while the form elements are styled to be clean and consistent. Here's the main styling.
Step 3. JavaScript Logic
The core functionality of the app lies in JavaScript. When the user submits their data, the script calculates BMI, adjusts caloric needs based on activity level, and provides workout suggestions accordingly. Here's a summary of the important steps.
- Convert Height to Centimeters: Since height is entered in feet and inches, the script converts it into centimeters to make calculations easier.
- Calculate BMI: The formula for BMI is weight / height², with height in meters.
- Calculate BMR: The Basal Metabolic Rate (BMR) is calculated using the Mifflin-St Jeor Equation, which differs for males and females.
- Adjust for Activity Level: The activity level multiplier is applied to BMR to calculate the daily caloric needs.
- Workout Recommendations: Based on age, BMI, and activity level, a personalized workout suggestion is generated.
Here’s how the JavaScript handles these calculations.
Step 4. Displaying Results
Once the form is submitted, the app displays the workout recommendation, the user’s BMI, and their daily caloric needs. The result is shown in a neat card with a dark background to emphasize the information.
Output
![Fitness tracker]()
Conclusion
This fitness tracker project showcases how HTML, CSS, and JavaScript can work together to create a user-friendly app that calculates BMI and daily caloric needs and provides personalized workout recommendations, making fitness more accessible and engaging.