Changed around line 1
+ // Initialize weight data
+ let weightData = [];
+ let goals = {
+ targetWeight: null,
+ timeFrame: null
+ };
+
+ // Chart setup
+ const ctx = document.getElementById('weightChart').getContext('2d');
+ const chart = new Chart(ctx, {
+ type: 'line',
+ data: {
+ labels: [],
+ datasets: [{
+ label: 'Weight (kg)',
+ data: [],
+ borderColor: '#4CAF50',
+ fill: false
+ }]
+ },
+ options: {
+ responsive: true,
+ maintainAspectRatio: false,
+ scales: {
+ y: {
+ beginAtZero: false
+ }
+ }
+ }
+ });
+
+ // Form submission handlers
+ document.getElementById('weightForm').addEventListener('submit', function(e) {
+ e.preventDefault();
+ const weight = parseFloat(document.getElementById('weightInput').value);
+ const date = new Date().toLocaleDateString();
+
+ weightData.push({ date, weight });
+ updateChart();
+ updateRecommendations();
+ this.reset();
+ });
+
+ document.getElementById('goalForm').addEventListener('submit', function(e) {
+ e.preventDefault();
+ goals.targetWeight = parseFloat(document.getElementById('targetWeight').value);
+ goals.timeFrame = parseInt(document.getElementById('timeFrame').value);
+ updateRecommendations();
+ this.reset();
+ });
+
+ // Update chart with new data
+ function updateChart() {
+ const labels = weightData.map(entry => entry.date);
+ const data = weightData.map(entry => entry.weight);
+
+ chart.data.labels = labels;
+ chart.data.datasets[0].data = data;
+ chart.update();
+ }
+
+ // Generate recommendations
+ function updateRecommendations() {
+ const recContent = document.getElementById('recommendationContent');
+
+ if (!weightData.length || !goals.targetWeight) {
+ recContent.innerHTML = '
Enter your goals to get personalized recommendations.
';
+ return;
+ }
+
+ const currentWeight = weightData[weightData.length - 1].weight;
+ const weightDifference = currentWeight - goals.targetWeight;
+ const weeklyGoal = weightDifference / goals.timeFrame;
+
+ let recommendation = `
Current Weight: ${currentWeight} kg
+
Target Weight: ${goals.targetWeight} kg
+
Weekly Goal: ${Math.abs(weeklyGoal.toFixed(1))} kg ${weeklyGoal > 0 ? 'loss' : 'gain'}
`;
+
+ if (weeklyGoal > 0) {
+ recommendation += `
Weight Loss Tips:
+
Create a calorie deficit of ${Math.round(weeklyGoal * 7700 / 7)} calories per day+
Increase physical activity+
Focus on whole, unprocessed foods+
Stay hydrated+ `;
+ } else {
+ recommendation += `
Weight Gain Tips:
+
Create a calorie surplus of ${Math.round(Math.abs(weeklyGoal) * 7700 / 7)} calories per day+
Focus on calorie-dense foods+
Incorporate strength training+
Eat frequent, balanced meals+ `;
+ }
+
+ recContent.innerHTML = recommendation;
+ }