Here’s a step-by-step walkthrough for building your Calisthenics Workout Tracker. We’ll create three files—index.html, style.css, and script.js—and I’ll explain what each part does as we go. Let’s get started! 🚀
Step 1: Create Your Project Folder
- Make a folder on your computer, e.g.
calisthenics-tracker/
- Inside it, create three empty files:
index.html
style.css
script.js
Step 2: Build the HTML (index.html)
This is the structure of your page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Calisthenics Workout Tracker</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<h1>Calisthenics Workout Tracker</h1>
<!-- 1) Log a New Workout -->
<section id="workout-log">
<h2>Log New Workout</h2>
<label>Date: <input type="date" id="workout-date" /></label>
<div class="exercise-input">
<input type="text" id="exercise-name" placeholder="Exercise Name" />
<input type="number" id="exercise-sets" placeholder="Sets" min="1" />
<input type="text" id="exercise-reps" placeholder="Reps (e.g. 10,8,6)" />
<button id="add-exercise-btn">Add Exercise</button>
</div>
<ul id="current-workout-exercises">
<!-- Dynamically added exercises show up here -->
</ul>
<button id="save-workout-btn">Save Workout</button>
<p id="workout-saved-message"></p>
</section>
<!-- 2) Workout History -->
<section id="workout-history">
<h2>Workout History</h2>
<ul id="workout-history-list">
<li class="no-workouts">No workouts logged yet.</li>
</ul>
</section>
</div>
<script src="script.js"></script>
</body>
</html>
Explanation
- The
<input type="date"> lets you pick a date for the workout.
- Three fields for the exercise: name, sets, and reps.
- “Add Exercise” pushes an exercise into the current workout list.
- “Save Workout” writes everything into localStorage and refreshes the history view.
Step 3: Style It (style.css)
A clean layout with some padding and colors.
/* Container */
body {
background: #f4f7f6;
font-family: sans-serif;
padding: 20px;
}
.container {
max-width: 700px;
margin: auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
/* Headings */
h1, h2 {
text-align: center;
color: #2c3e50;
}
/* Inputs & Buttons */
input, button {
padding: 8px;
margin: 5px 0;
border-radius: 4px;
border: 1px solid #ccc;
}
button {
cursor: pointer;
background: #3498db;
color: white;
border: none;
}
button:hover {
background: #2980b9;
}
/* Exercise List */
#current-workout-exercises,
#workout-history-list {
list-style: none;
padding: 0;
}
#current-workout-exercises li,
#workout-history-list li {
background: #ecf0f1;
margin: 5px 0;
padding: 8px;
border-radius: 4px;
display: flex;
justify-content: space-between;
}
/* Remove button */
.remove-exercise-btn {
background: #e74c3c;
padding: 4px 8px;
}
.remove-exercise-btn:hover {
background: #c0392b;
}
/* “No workouts” message */
.no-workouts {
text-align: center;
font-style: italic;
color: #7f8c8d;
}
Step 4: Add the Logic (script.js)
This script handles:
- State – current new-workout exercises and all saved workouts
- UI updates – render lists
- Persistence – load/save from
localStorage
document.addEventListener('DOMContentLoaded', () => {
// 1) Element refs
const dateInput = document.getElementById('workout-date');
const nameInput = document.getElementById('exercise-name');
const setsInput = document.getElementById('exercise-sets');
const repsInput = document.getElementById('exercise-reps');
const addBtn = document.getElementById('add-exercise-btn');
const saveBtn = document.getElementById('save-workout-btn');
const currentList = document.getElementById('current-workout-exercises');
const historyList = document.getElementById('workout-history-list');
const msgPara = document.getElementById('workout-saved-message');
// 2) State
let currentExercises = [];
let allWorkouts = [];
// 3) Load from localStorage
function loadWorkouts() {
const stored = localStorage.getItem('calisthenicsWorkouts');
if (stored) allWorkouts = JSON.parse(stored);
}
// 4) Save to localStorage
function saveWorkouts() {
localStorage.setItem('calisthenicsWorkouts', JSON.stringify(allWorkouts));
}
// 5) Render current new-workout list
function renderCurrent() {
currentList.innerHTML = '';
if (!currentExercises.length) {
currentList.innerHTML = '<li style="font-style:italic;color:#7f8c8d">No exercises added</li>';
return;
}
currentExercises.forEach((ex, idx) => {
const li = document.createElement('li');
li.innerHTML = `
${ex.name} — ${ex.sets} sets × ${ex.reps} reps
<button class="remove-exercise-btn" data-index="${idx}">✖</button>
`;
currentList.appendChild(li);
});
}
// 6) Render workout history
function renderHistory() {
historyList.innerHTML = '';
if (!allWorkouts.length) {
historyList.innerHTML = '<li class="no-workouts">No workouts logged yet.</li>';
return;
}
allWorkouts.forEach(w => {
const li = document.createElement('li');
li.innerHTML = `<strong>${w.date}</strong><ul>` +
w.exercises.map(e => `<li>${e.name} — ${e.sets}×${e.reps}</li>`).join('') +
`</ul>`;
historyList.appendChild(li);
});
}
// 7) Add Exercise handler
addBtn.addEventListener('click', () => {
const name = nameInput.value.trim();
const sets = parseInt(setsInput.value);
const reps = repsInput.value.trim();
if (!name || !sets || !reps) {
alert('Please fill all fields');
return;
}
currentExercises.push({name, sets, reps});
nameInput.value = setsInput.value = repsInput.value = '';
renderCurrent();
});
// 8) Remove exercise (event delegation)
currentList.addEventListener('click', e => {
if (e.target.matches('.remove-exercise-btn')) {
const i = +e.target.dataset.index;
currentExercises.splice(i, 1);
renderCurrent();
}
});
// 9) Save Workout handler
saveBtn.addEventListener('click', () => {
const date = dateInput.value;
if (!date) { alert('Pick a date'); return; }
if (!currentExercises.length) { alert('Add at least one exercise'); return; }
allWorkouts.push({ date, exercises: [...currentExercises] });
saveWorkouts();
renderHistory();
// clear current
currentExercises = [];
renderCurrent();
msgPara.textContent = 'Workout saved! 🎉';
setTimeout(() => msgPara.textContent = '', 2000);
});
// 10) Initialize
loadWorkouts();
renderCurrent();
renderHistory();
// Set default date = today
dateInput.valueAsDate = new Date();
});
How It Works
- On load, we read
localStorage into allWorkouts.
- Adding an exercise pushes data into
currentExercises and re-renders that list.
- Removing uses a data-index on the Remove button for quick splice.
- Saving builds a workout object
{ date, exercises: [...] }, appends it to allWorkouts, persists, then clears the “current” list.
- The history is re-rendered every time you save or load.
Step 5: Run & Test
- Open index.html in your browser.
- Pick a date, enter “Push-ups”, “3”, “10,9,8”, click Add Exercise.
- Add more exercises or click Save Workout.
- You should see your workout appear under Workout History.
- Close and reopen the tab—your data persists via
localStorage!
🎉 You now have a working Calisthenics Workout Tracker. From here, you can extend it—add edit/delete buttons, charts, or even hook up a backend for cross-device sync. Have fun, and happy training! 💪