Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ // Mobile menu toggle
+ const menuToggle = document.querySelector('.menu-toggle');
+ const navLinks = document.querySelector('.nav-links');
+
+ menuToggle?.addEventListener('click', () => {
+ navLinks.classList.toggle('active');
+ });
+
+ // Weight tracking functionality
+ const weightForm = document.getElementById('weight-form');
+ const weightChart = document.getElementById('weight-chart');
+
+ let weightData = JSON.parse(localStorage.getItem('weightData')) || [];
+
+ function updateChart() {
+ const ctx = weightChart.getContext('2d');
+ ctx.clearRect(0, 0, weightChart.width, weightChart.height);
+
+ if (weightData.length > 0) {
+ // Simple line chart implementation
+ ctx.beginPath();
+ ctx.moveTo(0, weightChart.height - (weightData[0].weight * 2));
+
+ weightData.forEach((data, index) => {
+ const x = (index / (weightData.length - 1)) * weightChart.width;
+ const y = weightChart.height - (data.weight * 2);
+ ctx.lineTo(x, y);
+ });
+
+ ctx.strokeStyle = '#3498db';
+ ctx.lineWidth = 2;
+ ctx.stroke();
+ }
+ }
+
+ function updateRecommendations() {
+ const recommendations = document.getElementById('diet-recommendations');
+ const latestWeight = weightData[weightData.length - 1]?.weight;
+ const goalWeight = document.getElementById('goal').value;
+
+ if (latestWeight && goalWeight) {
+ const diff = latestWeight - goalWeight;
+ let recommendationText = '';
+
+ if (diff > 0) {
+ recommendationText = `
+
+
Weight Loss Recommendations
+
Aim for a caloric deficit of 500 calories per day+
Increase protein intake to preserve muscle mass+
Include more vegetables in your meals+
Stay hydrated with at least 8 glasses of water daily+
+
+ `;
+ } else if (diff < 0) {
+ recommendationText = `
+
+
Weight Gain Recommendations
+
Increase caloric intake by 500 calories per day+
Focus on nutrient-dense foods+
Include healthy fats in your diet+
Consume protein-rich foods with each meal+
+
+ `;
+ } else {
+ recommendationText = `
+
+
Maintenance Recommendations
+
Maintain current caloric intake+
Focus on balanced nutrition+
Stay active and consistent with exercise+
Monitor weight weekly+
+
+ `;
+ }
+
+ recommendations.innerHTML = recommendationText;
+ }
+ }
+
+ weightForm?.addEventListener('submit', (e) => {
+ e.preventDefault();
+ const weight = parseFloat(document.getElementById('weight').value);
+ const date = new Date().toISOString();
+
+ weightData.push({ weight, date });
+ localStorage.setItem('weightData', JSON.stringify(weightData));
+
+ updateChart();
+ updateRecommendations();
+ });
+
+ // Initialize chart and recommendations
+ updateChart();
+ updateRecommendations();
+ });