The Ultimate Guide to Using a Daily Diet Tracker for Better Health

Maintaining a healthy diet is essential for overall well-being, but keeping track of what you eat can be challenging. A Daily Diet Tracker is a powerful tool that helps you monitor your food intake, stay accountable, and make informed dietary choices. Whether your goal is weight loss, muscle gain, or simply improving your eating habits, a diet tracker can be a game-changer.



Why Use a Daily Diet Tracker?

Promotes Awareness – Many people underestimate or overestimate their food intake. Tracking helps you see exactly what and how much you’re consuming.

Encourages Accountability – Logging meals keeps you mindful of your choices, reducing mindless snacking.

Helps Identify Patterns – You can spot trends like emotional eating, nutrient deficiencies, or excessive sugar intake.

Supports Weight Management – Whether losing, gaining, or maintaining weight, tracking calories and macros ensures you stay on target.

Improves Nutritional Balance – A diet tracker helps ensure you’re getting enough protein, fiber, vitamins, and minerals.

How to Use a Daily Diet Tracker Effectively

1. Choose Your Tracking Method

Mobile Apps (MyFitnessPal, Cronometer, Lose It!) – Easy to use with barcode scanning and large food databases.

Journal/Notebook – Writing down meals manually can be effective for those who prefer a non-digital approach.

Spreadsheets (Excel/Google Sheets) – Customizable for tracking macros, calories, and meal timings.

2. Record Everything You Eat and Drink

Be honest and include snacks, beverages, and even small bites.

Measure portions accurately using a food scale or measuring cups.

3. Track Key Nutritional Metrics

Calories – Ensure you’re in a deficit, surplus, or maintenance based on your goals.

Macronutrients (Carbs, Proteins, Fats) – Adjust ratios based on activity levels (e.g., high protein for muscle building).

Micronutrients (Vitamins & Minerals) – Check if you’re meeting daily requirements for iron, calcium, vitamin D, etc.

4. Review and Adjust

Analyze weekly logs to see where improvements can be made.

Adjust portion sizes or food choices if you’re consistently over or under your targets.

Tips for Success

✅ Plan Meals in Advance – Pre-logging meals prevents last-minute unhealthy choices.

✅ Stay Consistent – Track daily, even on weekends or cheat days, for accurate insights.

✅ Listen to Your Body – Use hunger cues alongside tracking to avoid over-restriction.

✅ Celebrate Progress – Small wins (like hitting protein goals) keep motivation high.


Sample Daily Diet Tracker Entry

MealFood ItemCaloriesProtein (g)Carbs (g)Fats (g)
BreakfastOatmeal + Banana + Almond Butter350105012
LunchGrilled Chicken + Quinoa + Veggies450354010
SnackGreek Yogurt + Berries15012202
DinnerSalmon + Sweet Potato + Broccoli500304518
Total145087155

Final Thoughts

A Daily Diet Tracker is a simple yet effective way to take control of your nutrition. By consistently logging meals, you’ll develop healthier habits, make better food choices, and ultimately reach your health goals faster. Start tracking today and see the difference it makes!

HTML Script

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>NutriTrack Pro</title>

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css">

    <style>

        :root {

            --primary: #FF0000;

            --secondary: #D10000;

            --dark: #000000;

            --light: #1A1A1A;

            --text: #FFFFFF;

            --accent: #FF3333;

        }

        

        * {

            box-sizing: border-box;

            margin: 0;

            padding: 0;

        }

        

        body {

            font-family: 'Montserrat', sans-serif;

            background-color: var(--dark);

            color: var(--text);

            line-height: 1.6;

            overflow-x: hidden;

        }

        

        .container {

            max-width: 1200px;

            margin: 0 auto;

            padding: 20px;

        }

        

        header {

            background: linear-gradient(135deg, var(--dark), var(--light));

            padding: 30px 0;

            text-align: center;

            position: relative;

            overflow: hidden;

            box-shadow: 0 10px 30px rgba(255, 0, 0, 0.2);

        }

        

        header::before {

            content: '';

            position: absolute;

            top: 0;

            left: 0;

            width: 100%;

            height: 5px;

            background: var(--primary);

            animation: headerGlow 3s infinite;

        }

        

        @keyframes headerGlow {

            0% { box-shadow: 0 0 10px var(--primary); }

            50% { box-shadow: 0 0 20px var(--primary); }

            100% { box-shadow: 0 0 10px var(--primary); }

        }

        

        h1 {

            font-size: 3rem;

            margin: 0;

            background: linear-gradient(to right, var(--primary), var(--accent));

            -webkit-background-clip: text;

            background-clip: text;

            color: transparent;

            text-transform: uppercase;

            letter-spacing: 2px;

            animation: fadeInDown 1s;

        }

        

        .tagline {

            font-size: 1.2rem;

            margin-top: 10px;

            color: #AAA;

            animation: fadeIn 1.5s;

        }

        

        .upload-section {

            background-color: var(--light);

            padding: 30px;

            border-radius: 15px;

            margin: 40px 0;

            box-shadow: 0 10px 20px rgba(0,0,0,0.3);

            text-align: center;

            border: 1px solid var(--primary);

            transform-style: preserve-3d;

            transition: all 0.5s ease;

            animation: slideInUp 1s;

        }

        

        .upload-section:hover {

            transform: translateY(-5px);

            box-shadow: 0 15px 30px rgba(255, 0, 0, 0.3);

        }

        

        .section-title {

            font-size: 1.8rem;

            margin-bottom: 20px;

            color: var(--primary);

            position: relative;

            display: inline-block;

        }

        

        .section-title::after {

            content: '';

            position: absolute;

            bottom: -10px;

            left: 0;

            width: 100%;

            height: 3px;

            background: var(--primary);

            transform: scaleX(0);

            transform-origin: left;

            transition: transform 0.3s;

        }

        

        .upload-section:hover .section-title::after {

            transform: scaleX(1);

        }

        

        #imagePreview {

            max-width: 100%;

            max-height: 400px;

            margin: 25px 0;

            border-radius: 10px;

            display: none;

            border: 3px solid var(--primary);

            box-shadow: 0 5px 15px rgba(0,0,0,0.5);

            transition: all 0.3s;

        }

        

        #imagePreview:hover {

            transform: scale(1.02);

            box-shadow: 0 10px 25px rgba(255, 0, 0, 0.4);

        }

        

        .upload-btn {

            background: linear-gradient(45deg, var(--primary), var(--accent));

            color: white;

            border: none;

            padding: 15px 30px;

            border-radius: 50px;

            cursor: pointer;

            font-size: 18px;

            font-weight: bold;

            transition: all 0.3s;

            box-shadow: 0 5px 15px rgba(255, 0, 0, 0.3);

            text-transform: uppercase;

            letter-spacing: 1px;

            position: relative;

            overflow: hidden;

        }

        

        .upload-btn:hover {

            transform: translateY(-3px);

            box-shadow: 0 8px 20px rgba(255, 0, 0, 0.4);

        }

        

        .upload-btn:active {

            transform: translateY(1px);

        }

        

        .upload-btn::after {

            content: '';

            position: absolute;

            top: 0;

            left: 0;

            width: 100%;

            height: 100%;

            background: linear-gradient(45deg, transparent, rgba(255,255,255,0.2), transparent);

            transform: translateX(-100%);

            transition: transform 0.6s;

        }

        

        .upload-btn:hover::after {

            transform: translateX(100%);

        }

        

        .nutrition-display {

            display: grid;

            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));

            gap: 20px;

            margin: 40px 0;

            animation: fadeIn 1s;

        }

        

        .nutrition-card {

            background-color: var(--light);

            padding: 25px;

            border-radius: 15px;

            box-shadow: 0 5px 15px rgba(0,0,0,0.3);

            text-align: center;

            transition: all 0.3s;

            border-top: 3px solid var(--primary);

            position: relative;

            overflow: hidden;

        }

        

        .nutrition-card:hover {

            transform: translateY(-10px);

            box-shadow: 0 15px 30px rgba(255, 0, 0, 0.2);

        }

        

        .nutrition-card::before {

            content: '';

            position: absolute;

            top: 0;

            left: 0;

            width: 100%;

            height: 100%;

            background: linear-gradient(45deg, transparent, rgba(255, 0, 0, 0.05), transparent);

            transform: translateX(-100%);

            transition: transform 0.6s;

        }

        

        .nutrition-card:hover::before {

            transform: translateX(100%);

        }

        

        .nutrition-value {

            font-size: 2.5rem;

            font-weight: bold;

            color: var(--primary);

            margin: 10px 0;

            text-shadow: 0 0 10px rgba(255, 0, 0, 0.3);

        }

        

        .nutrition-label {

            font-size: 16px;

            color: #AAA;

            text-transform: uppercase;

            letter-spacing: 1px;

        }

        

        .daily-summary {

            background: linear-gradient(135deg, var(--light), var(--dark));

            padding: 30px;

            border-radius: 15px;

            margin-top: 40px;

            box-shadow: 0 10px 30px rgba(0,0,0,0.3);

            border: 1px solid var(--primary);

            animation: fadeIn 1s;

        }

        

        .progress-container {

            background-color: rgba(0,0,0,0.5);

            border-radius: 10px;

            margin: 20px 0;

            height: 25px;

            overflow: hidden;

            box-shadow: inset 0 1px 3px rgba(0,0,0,0.2);

        }

        

        .progress-bar {

            background: linear-gradient(90deg, var(--primary), var(--accent));

            height: 100%;

            border-radius: 10px;

            width: 0%;

            transition: width 0.8s cubic-bezier(0.68, -0.55, 0.265, 1.55);

            position: relative;

            overflow: hidden;

        }

        

        .progress-bar::after {

            content: '';

            position: absolute;

            top: 0;

            left: 0;

            width: 100%;

            height: 100%;

            background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);

            animation: progressShine 2s infinite;

        }

        

        @keyframes progressShine {

            0% { transform: translateX(-100%); }

            100% { transform: translateX(100%); }

        }

        

        .history {

            margin-top: 50px;

            animation: fadeIn 1s;

        }

        

        .history-item {

            background-color: var(--light);

            padding: 25px;

            border-radius: 15px;

            margin-bottom: 20px;

            box-shadow: 0 5px 15px rgba(0,0,0,0.3);

            transition: all 0.3s;

            border-left: 5px solid var(--primary);

            position: relative;

            overflow: hidden;

        }

        

        .history-item:hover {

            transform: translateX(10px);

            box-shadow: 0 10px 25px rgba(255, 0, 0, 0.2);

        }

        

        .history-item h3 {

            margin-top: 0;

            color: var(--primary);

            font-size: 1.5rem;

            margin-bottom: 10px;

        }

        

        .history-time {

            font-size: 14px;

            color: #AAA;

            margin-left: 10px;

        }

        

        .history-nutrition {

            display: flex;

            flex-wrap: wrap;

            gap: 10px;

            margin-top: 15px;

        }

        

        .history-nutrition span {

            background-color: rgba(255, 0, 0, 0.1);

            padding: 5px 15px;

            border-radius: 20px;

            font-size: 14px;

            color: var(--primary);

            border: 1px solid rgba(255, 0, 0, 0.3);

        }

        

        .disclaimer {

            background-color: rgba(255, 0, 0, 0.1);

            padding: 20px;

            border-radius: 10px;

            margin-top: 50px;

            border: 1px solid var(--primary);

            font-size: 14px;

            color: #AAA;

            animation: fadeIn 1s;

        }

        

        .disclaimer h3 {

            color: var(--primary);

            margin-bottom: 10px;

        }

        

        .pulse {

            animation: pulse 2s infinite;

        }

        

        @keyframes pulse {

            0% { transform: scale(1); }

            50% { transform: scale(1.05); }

            100% { transform: scale(1); }

        }

        

        .floating {

            animation: floating 3s ease-in-out infinite;

        }

        

        @keyframes floating {

            0% { transform: translateY(0px); }

            50% { transform: translateY(-10px); }

            100% { transform: translateY(0px); }

        }

        

        @media (max-width: 768px) {

            h1 {

                font-size: 2rem;

            }

            

            .nutrition-display {

                grid-template-columns: 1fr 1fr;

            }

            

            .upload-btn {

                padding: 12px 24px;

                font-size: 16px;

            }

        }

        

        @media (max-width: 480px) {

            .nutrition-display {

                grid-template-columns: 1fr;

            }

            

            .container {

                padding: 15px;

            }

            

            .upload-section {

                padding: 20px;

            }

        }

    </style>

    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600;700&display=swap" rel="stylesheet">

</head>

<body>

    <header class="animate__animated animate__fadeIn">

        <div class="container">

            <h1>NutriTrack Pro</h1>

            <p class="tagline">Track your nutrition with precision and style</p>

        </div>

techpk

    </header>

    

    <div class="container">

        <div class="upload-section animate__animated animate__fadeInUp">

            <h2 class="section-title">Upload Your Meal</h2>

            <input type="file" id="imageUpload" accept="image/*" style="display: none;">

            <button class="upload-btn pulse" id="uploadBtn">Choose Food Image</button>

            <img id="imagePreview" class="animate__animated" alt="Food preview">

            <button class="upload-btn" id="analyzeBtn" style="display: none; margin-top: 20px;">Analyze Nutrition</button>

        </div>

        techpk

        <div class="daily-summary animate__animated animate__fadeIn">

            <h2 class="section-title">Today's Nutrition</h2>

            <div class="progress-container">

                <div class="progress-bar" id="calorieProgress"></div>

            </div>

            <p style="font-size: 1.2rem; margin-top: 10px;">Calories: <span id="totalCalories" style="color: var(--primary); font-weight: bold;">0</span>/2000 kcal</p>

        </div>

        techpk

        <div class="nutrition-display animate__animated animate__fadeIn">

            <div class="nutrition-card floating" style="animation-delay: 0.1s;">

                <div class="nutrition-value" id="proteinValue">0</div>

                <div class="nutrition-label">Protein (g)</div>

            </div>

            <div class="nutrition-card floating" style="animation-delay: 0.2s;">

                <div class="nutrition-value" id="carbsValue">0</div>

                <div class="nutrition-label">Carbs (g)</div>

            </div>

            <div class="nutrition-card floating" style="animation-delay: 0.3s;">

                <div class="nutrition-value" id="fatsValue">0</div>

                <div class="nutrition-label">Fats (g)</div>

            </div>

            <div class="nutrition-card floating" style="animation-delay: 0.4s;">

                <div class="nutrition-value" id="fiberValue">0</div>

                <div class="nutrition-label">Fiber (g)</div>

            </div>

            <div class="nutrition-card floating" style="animation-delay: 0.5s;">

                <div class="nutrition-value" id="sugarValue">0</div>

                <div class="nutrition-label">Sugar (g)</div>

            </div>

            <div class="nutrition-card floating" style="animation-delay: 0.6s;">

                <div class="nutrition-value" id="sodiumValue">0</div>

                <div class="nutrition-label">Sodium (mg)</div>

            </div>

        </div>

        techpk

        <div class="history animate__animated animate__fadeIn">

            <h2 class="section-title">Meal History</h2>

            <div id="historyList"></div>

        </div>

techpk

        

        <div class="disclaimer animate__animated animate__fadeIn">

            <h3>Disclaimer</h3>

            <p>This application provides estimated nutritional information based on image analysis and should not be considered as medical or dietary advice. The results are simulated for demonstration purposes and may not be accurate. Always consult with a qualified healthcare professional for dietary guidance.</p>

        </div>

    </div>

    

    <script>

        // DOM elements

        const uploadBtn = document.getElementById('uploadBtn');

        const analyzeBtn = document.getElementById('analyzeBtn');

        const imageUpload = document.getElementById('imageUpload');

        const imagePreview = document.getElementById('imagePreview');

        const historyList = document.getElementById('historyList');

        

        // Nutrition display elements

        const totalCalories = document.getElementById('totalCalories');

        const proteinValue = document.getElementById('proteinValue');

        const carbsValue = document.getElementById('carbsValue');

        const fatsValue = document.getElementById('fatsValue');

        const fiberValue = document.getElementById('fiberValue');

        const sugarValue = document.getElementById('sugarValue');

        const sodiumValue = document.getElementById('sodiumValue');

        const calorieProgress = document.getElementById('calorieProgress');

        

        // Global variables

        let dailyNutrition = {

            calories: 0,

            protein: 0,

            carbs: 0,

            fats: 0,

            fiber: 0,

            sugar: 0,

            sodium: 0

        };

        

        let mealHistory = [];

        

        // Event listeners

        uploadBtn.addEventListener('click', () => imageUpload.click());

        

        imageUpload.addEventListener('change', function(e) {

            if (e.target.files.length > 0) {

                const file = e.target.files[0];

                const reader = new FileReader();

                

                reader.onload = function(event) {

                    imagePreview.src = event.target.result;

                    imagePreview.style.display = 'block';

                    imagePreview.classList.add('animate__fadeIn');

                    analyzeBtn.style.display = 'inline-block';

                    analyzeBtn.classList.add('pulse');

                };

                

                reader.readAsDataURL(file);

            }

        });

        

        analyzeBtn.addEventListener('click', function() {

            this.classList.remove('pulse');

            analyzeImage();

        });

        

        // Functions

        function analyzeImage() {

            // Add loading animation

            analyzeBtn.textContent = 'Analyzing...';

            analyzeBtn.style.background = 'linear-gradient(45deg, var(--light), var(--dark))';

            

            // Simulate analysis delay

            setTimeout(() => {

                // Simulate image analysis with random values

                const mealName = generateRandomMealName();

                const nutrition = generateRandomNutrition();

                

                // Add to daily totals

                dailyNutrition.calories += nutrition.calories;

                dailyNutrition.protein += nutrition.protein;

                dailyNutrition.carbs += nutrition.carbs;

                dailyNutrition.fats += nutrition.fats;

                dailyNutrition.fiber += nutrition.fiber;

                dailyNutrition.sugar += nutrition.sugar;

                dailyNutrition.sodium += nutrition.sodium;

                

                // Update UI

                updateNutritionDisplay();

                

                // Add to history

                addToHistory(mealName, nutrition);

                

                // Reset upload

                imageUpload.value = '';

                imagePreview.style.display = 'none';

                analyzeBtn.style.display = 'none';

                analyzeBtn.textContent = 'Analyze Nutrition';

                analyzeBtn.style.background = 'linear-gradient(45deg, var(--primary), var(--accent))';

                

                // Add success animation

                const success = document.createElement('div');

                success.textContent = '✓ Analysis Complete!';

                success.style.position = 'fixed';

                success.style.bottom = '20px';

                success.style.right = '20px';

                success.style.backgroundColor = 'var(--primary)';

                success.style.color = 'white';

                success.style.padding = '15px 25px';

                success.style.borderRadius = '5px';

                success.style.boxShadow = '0 5px 15px rgba(0,0,0,0.3)';

                success.style.zIndex = '1000';

                success.style.animation = 'fadeIn 0.5s';

                document.body.appendChild(success);

                

                setTimeout(() => {

                    success.style.animation = 'fadeOut 0.5s';

                    setTimeout(() => document.body.removeChild(success), 500);

                }, 3000);

            }, 1500);

        }

        

        function updateNutritionDisplay() {

            // Animate the number changes

            animateValue(totalCalories, parseInt(totalCalories.textContent), dailyNutrition.calories, 1000);

            animateValue(proteinValue, parseFloat(proteinValue.textContent), dailyNutrition.protein, 1000);

            animateValue(carbsValue, parseFloat(carbsValue.textContent), dailyNutrition.carbs, 1000);

            animateValue(fatsValue, parseFloat(fatsValue.textContent), dailyNutrition.fats, 1000);

            animateValue(fiberValue, parseFloat(fiberValue.textContent), dailyNutrition.fiber, 1000);

            animateValue(sugarValue, parseFloat(sugarValue.textContent), dailyNutrition.sugar, 1000);

            animateValue(sodiumValue, parseFloat(sodiumValue.textContent), dailyNutrition.sodium, 1000);

            

            // Update progress bar (max 2000 calories)

            const progressPercent = Math.min((dailyNutrition.calories / 2000) * 100, 100);

            calorieProgress.style.width = `${progressPercent}%`;

            

            // Add pulse animation to changed values

            const cards = document.querySelectorAll('.nutrition-card');

            cards.forEach(card => card.classList.add('pulse'));

            setTimeout(() => cards.forEach(card => card.classList.remove('pulse')), 1000);

        }

        

        function animateValue(element, start, end, duration) {

            let startTimestamp = null;

            const step = (timestamp) => {

                if (!startTimestamp) startTimestamp = timestamp;

                const progress = Math.min((timestamp - startTimestamp) / duration, 1);

                const value = Math.floor(progress * (end - start) + start);

                if (element === proteinValue || element === carbsValue || element === fatsValue || 

                    element === fiberValue || element === sugarValue) {

                    element.textContent = value.toFixed(1);

                } else if (element === sodiumValue) {

                    element.textContent = Math.round(value);

                } else {

                    element.textContent = value;

                }

                if (progress < 1) {

                    window.requestAnimationFrame(step);

                }

            };

            window.requestAnimationFrame(step);

        }

        

        function addToHistory(mealName, nutrition) {

            mealHistory.unshift({

                name: mealName,

                nutrition: nutrition,

                time: new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })

            });

            

            renderHistory();

        }

        

        function renderHistory() {

            historyList.innerHTML = '';

            

            mealHistory.forEach((meal, index) => {

                const item = document.createElement('div');

                item.className = 'history-item animate__animated animate__fadeIn';

                item.style.animationDelay = `${index * 0.1}s`;

                

                item.innerHTML = `

                    <h3>${meal.name} <span class="history-time">${meal.time}</span></h3>

                    <div class="history-nutrition">

                        <span>${meal.nutrition.calories} kcal</span>

                        <span>Protein: ${meal.nutrition.protein.toFixed(1)}g</span>

                        <span>Carbs: ${meal.nutrition.carbs.toFixed(1)}g</span>

                        <span>Fat: ${meal.nutrition.fats.toFixed(1)}g</span>

                        ${meal.nutrition.fiber > 3 ? `<span>Fiber: ${meal.nutrition.fiber.toFixed(1)}g</span>` : ''}

                        ${meal.nutrition.sugar > 10 ? `<span>Sugar: ${meal.nutrition.sugar.toFixed(1)}g</span>` : ''}

                    </div>

                `;

                

                historyList.appendChild(item);

            });

        }

        

        // Random generators

        function generateRandomMealName() {

            const meals = [

                "Spicy Chicken Salad", "Creamy Pasta Carbonara", "Asian Vegetable Stir Fry", 

                "Gourmet Beef Burger", "Grilled Salmon with Rice", "Hearty Vegetable Soup",

                "Four Cheese Pizza", "Authentic Greek Salad", "Premium Tuna Sandwich",

                "Avocado Toast Deluxe", "Three Cheese Omelette", "Exotic Fruit Bowl",

                "BBQ Ribs Platter", "Mediterranean Platter", "Sushi Combo"

            ];

            

            return meals[Math.floor(Math.random() * meals.length)];

        }

        

        function generateRandomNutrition() {

            // More sophisticated random generation with food type consideration

            const foodType = Math.random();

            

            let baseCalories, proteinRatio, fatRatio;

            

            if (foodType < 0.3) { // Protein-rich foods

                baseCalories = 400 + Math.random() * 400;

                proteinRatio = 0.35 + Math.random() * 0.15;

                fatRatio = 0.25 + Math.random() * 0.15;

            } else if (foodType < 0.6) { // Carb-rich foods

                baseCalories = 500 + Math.random() * 500;

                proteinRatio = 0.15 + Math.random() * 0.1;

                fatRatio = 0.2 + Math.random() * 0.1;

            } else { // Balanced meals

                baseCalories = 450 + Math.random() * 450;

                proteinRatio = 0.25 + Math.random() * 0.1;

                fatRatio = 0.3 + Math.random() * 0.1;

            }

            

            const carbRatio = 1 - proteinRatio - fatRatio;

            

            // Calculate macros (4 cal/g protein & carbs, 9 cal/g fat)

            const protein = (baseCalories * proteinRatio) / 4;

            const fats = (baseCalories * fatRatio) / 9;

            const carbs = (baseCalories * carbRatio) / 4;

            

            // Other nutrients with some relation to the macros

            const fiber = carbs * (0.1 + Math.random() * 0.3);

            const sugar = carbs * (0.1 + Math.random() * 0.4);

            const sodium = 150 + Math.random() * 1000;

            

            return {

                calories: Math.round(baseCalories),

                protein: protein,

                carbs: carbs,

                fats: fats,

                fiber: fiber,

                sugar: sugar,

                sodium: sodium

            };

        }

        

        // Initialize with some random history for demo

        function initializeDemoData() {

            const demoMeals = 3 + Math.floor(Math.random() * 3);

            

            for (let i = 0; i < demoMeals; i++) {

                const mealName = generateRandomMealName();

                const nutrition = generateRandomNutrition();

                

                dailyNutrition.calories += nutrition.calories;

                dailyNutrition.protein += nutrition.protein;

                dailyNutrition.carbs += nutrition.carbs;

                dailyNutrition.fats += nutrition.fats;

                dailyNutrition.fiber += nutrition.fiber;

                dailyNutrition.sugar += nutrition.sugar;

                dailyNutrition.sodium += nutrition.sodium;

                

                mealHistory.push({

                    name: mealName,

                    nutrition: nutrition,

                    time: new Date(Date.now() - (i * 3 * 60 * 60 * 1000)).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })

                });

            }

            

            updateNutritionDisplay();

            renderHistory();

        }

        

        // Initialize the app

        initializeDemoData();

        

        // Add floating animation to nutrition cards on hover

        document.querySelectorAll('.nutrition-card').forEach(card => {

            card.addEventListener('mouseenter', function() {

                this.classList.add('floating');

            });

            

            card.addEventListener('mouseleave', function() {

                this.classList.remove('floating');

            });

        });

    </script>

</body>

</html>


 

No comments:

Post a Comment

If you have any question you can ask me feelfree.