This project provides a simple workout tracker web application. The application allows users to log their workouts and view their workout history and total calories burned.
- index.html: The main HTML file containing the structure of the application.
- styles.css: The CSS file responsible for styling the application's appearance.
- script.js: The JavaScript file containing the application's logic and functionality.
- DOCTYPE Declaration: Defines the document type as HTML5.
- HTML Tag: The root element of the HTML document.
- Head Section: Contains metadata about the document.
- charset: Sets the character encoding to UTF-8 for proper display of various characters.
- viewport: Defines the viewport for responsive design, ensuring proper rendering across devices.
- title: Sets the title of the HTML document, displayed in the browser tab.
- link: Links the
styles.cssfile for styling the page.
- Body Section: Contains the visible content of the page.
- Container: A
divelement to group the application's content for styling purposes.- Heading: An
h1element displaying the application's title "Workout Tracker." - Workout Form (
workoutForm):- A
formelement to collect workout details from the user. - Form Groups:
divelements used to group the labels and input fields.- Labels:
labelelements for each input field, providing descriptive text. - Input Fields:
- Type:
inputfield of type "text" to accept the workout type. - Duration:
inputfield of type "number" to accept the workout duration in minutes. - Intensity:
selectelement allowing users to choose from "Low," "Medium," or "High" intensity levels. - Calories Burned:
inputfield of type "number" to accept the calories burned during the workout.
- Type:
- Labels:
- Submit Button:
buttonelement withsubmittype to trigger the form submission.
- A
- Workout History Section:
- Heading:
h2element titled "Workout History." - Workout List (
workoutList): Adivelement where workout history will be displayed.
- Heading:
- Total Calories Burned Section:
- Heading:
h2element titled "Total Calories Burned." - Total Calories (
totalCalories): Apelement displaying the total calories burned.
- Heading:
- Heading: An
- Container: A
- Script Tag: Links the
script.jsfile for functionality.
The styles.css file contains CSS rules to style the elements of the HTML document, ensuring a visually appealing and user-friendly interface.
- General Styling:
- Sets basic styles for the body, container, headings, and form elements.
- Form Styling:
- Styles the form elements like input fields, labels, and the submit button.
- Workout History Styling:
- Styles the "Workout History" section, including the list of workouts.
- Total Calories Styling:
- Styles the "Total Calories Burned" section.
The script.js file contains JavaScript code that handles the functionality of the Workout Tracker application.
-
Event Listener:
- Attaches an event listener to the "Log Workout" button (
workoutForm) to trigger thehandleSubmitfunction on form submission.
- Attaches an event listener to the "Log Workout" button (
-
handleSubmit Function:
- Retrieves data from the form input fields.
- Validates the input data to ensure it's in the correct format.
- Creates a new workout object containing the retrieved data.
- Adds the new workout object to the
workoutHistoryarray. - Updates the total calories burned.
- Clears the form for the user to log another workout.
- Renders the workout history in the
workoutListsection. - Updates the total calories burned in the
totalCalorieselement.
-
renderWorkoutHistory Function:
- Clears the previous workout history content from the
workoutListelement. - Iterates through the
workoutHistoryarray. - For each workout in the array, it creates a new
divelement to display the workout details. - Appends the newly created
divelement to theworkoutListelement.
- Clears the previous workout history content from the
-
updateTotalCalories Function:
- Calculates the total calories burned by summing the calories burned from all workouts in the
workoutHistoryarray. - Updates the
totalCalorieselement with the new total calories burned.
- Calculates the total calories burned by summing the calories burned from all workouts in the
This documentation provides a comprehensive overview of the Workout Tracker application, explaining each file and its purpose. The code is well-organized and commented, allowing for easy understanding and modification.