|
4 | 4 | <meta charset="UTF-8" /> |
5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1" /> |
6 | 6 | <meta http-equiv="X-UA-Compatible" content="ie=edge" /> |
7 | | - <title>BMI Calculator</title> |
| 7 | + <title>BMI Calculator & Diet Planner</title> |
8 | 8 | <style> |
9 | | - /* Simple styles for the form and container */ |
| 9 | + body { |
| 10 | + margin: 0; |
| 11 | + padding: 0; |
| 12 | + font-family: Arial, sans-serif; |
| 13 | + background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%); |
| 14 | + height: 100vh; |
| 15 | + display: flex; |
| 16 | + justify-content: center; |
| 17 | + align-items: center; |
| 18 | + } |
10 | 19 | .container { |
| 20 | + background: rgba(255, 255, 255, 0.9); |
| 21 | + border-radius: 12px; |
| 22 | + box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15); |
11 | 23 | max-width: 400px; |
12 | | - margin: 50px auto; |
13 | | - padding: 20px; |
14 | | - font-family: Arial, sans-serif; |
15 | | - border: 1px solid #ccc; |
16 | | - border-radius: 8px; |
| 24 | + width: 90%; |
| 25 | + padding: 30px 35px; |
| 26 | + text-align: center; |
17 | 27 | } |
18 | | - input[type="text"] { |
| 28 | + input[type="text"], select { |
19 | 29 | width: 100%; |
20 | | - padding: 8px; |
21 | | - margin-top: 5px; |
22 | | - margin-bottom: 15px; |
23 | | - box-sizing: border-box; |
24 | | - border-radius: 4px; |
| 30 | + padding: 10px; |
| 31 | + margin: 10px 0 20px 0; |
25 | 32 | border: 1px solid #ccc; |
| 33 | + border-radius: 6px; |
| 34 | + font-size: 16px; |
| 35 | + box-sizing: border-box; |
| 36 | + transition: all 0.3s ease; |
| 37 | + } |
| 38 | + input[type="text"]:focus, select:focus { |
| 39 | + border-color: #ff6f91; |
| 40 | + outline: none; |
| 41 | + box-shadow: 0 0 8px rgba(255, 111, 145, 0.6); |
26 | 42 | } |
27 | 43 | button { |
28 | | - padding: 10px 15px; |
29 | | - border-radius: 4px; |
| 44 | + background-color: #ff6f91; |
30 | 45 | border: none; |
31 | | - background-color: #007bff; |
| 46 | + padding: 12px 25px; |
32 | 47 | color: white; |
| 48 | + font-size: 18px; |
| 49 | + border-radius: 8px; |
33 | 50 | cursor: pointer; |
34 | | - font-size: 16px; |
| 51 | + transition: background-color 0.3s ease; |
| 52 | + margin-top: 10px; |
| 53 | + width: 100%; |
35 | 54 | } |
36 | 55 | button:hover { |
37 | | - background-color: #0056b3; |
| 56 | + background-color: #ff4a70; |
| 57 | + } |
| 58 | + h1 { |
| 59 | + margin-bottom: 20px; |
| 60 | + color: #333; |
| 61 | + font-weight: 700; |
38 | 62 | } |
39 | 63 | #results { |
40 | 64 | margin-top: 20px; |
41 | | - font-weight: bold; |
42 | | - color: #333; |
| 65 | + font-weight: 600; |
| 66 | + font-size: 18px; |
| 67 | + color: #444; |
| 68 | + min-height: 70px; |
| 69 | + } |
| 70 | + #weight-guide { |
| 71 | + margin-top: 25px; |
| 72 | + background-color: #ffe7f0; |
| 73 | + border-radius: 8px; |
| 74 | + padding: 15px; |
| 75 | + color: #a63c53; |
| 76 | + text-align: left; |
| 77 | + font-weight: 600; |
| 78 | + box-shadow: inset 0 0 10px #ffafb8; |
43 | 79 | } |
44 | 80 | #weight-guide h3 { |
45 | | - margin-bottom: 6px; |
| 81 | + margin-bottom: 8px; |
| 82 | + color: #ff6f91; |
46 | 83 | } |
47 | 84 | </style> |
48 | 85 | </head> |
49 | 86 | <body> |
50 | 87 | <div class="container"> |
51 | | - <h1>BMI Calculator</h1> |
| 88 | + <h1>BMI Calculator & Diet Planner</h1> |
52 | 89 | <form id="bmi-form"> |
53 | | - <label><b>Height (cm):</b></label> |
54 | 90 | <input type="text" id="height" placeholder="Enter height in cm" /> |
55 | | - <label><b>Weight (kg):</b></label> |
56 | 91 | <input type="text" id="weight" placeholder="Enter weight in kg" /> |
57 | | - <button type="submit">Calculate</button> |
| 92 | + <select id="activity-level"> |
| 93 | + <option value="sedentary">Sedentary</option> |
| 94 | + <option value="light">Lightly Active</option> |
| 95 | + <option value="moderate">Moderate</option> |
| 96 | + <option value="active">Active</option> |
| 97 | + </select> |
| 98 | + <button type="submit">Get Recommendation</button> |
58 | 99 | <div id="results"></div> |
59 | 100 | <div id="weight-guide"> |
60 | 101 | <h3>BMI Weight Guide</h3> |
61 | | - <p>Under Weight = Less than 18.6</p> |
62 | | - <p>Normal Range = 18.6 and 24.9</p> |
63 | | - <p>Overweight = Greater than 24.9</p> |
| 102 | + <p>Underweight: Less than 18.6</p> |
| 103 | + <p>Normal: 18.6 to 24.9</p> |
| 104 | + <p>Overweight: Greater than 24.9</p> |
64 | 105 | </div> |
65 | 106 | </form> |
66 | 107 | </div> |
67 | 108 |
|
68 | 109 | <script> |
69 | | - document.getElementById('bmi-form').addEventListener('submit', function (event) { |
| 110 | + document.getElementById('bmi-form').addEventListener('submit', function(event) { |
70 | 111 | event.preventDefault(); |
71 | 112 |
|
72 | 113 | const heightInput = document.getElementById('height').value.trim(); |
73 | 114 | const weightInput = document.getElementById('weight').value.trim(); |
| 115 | + const activity = document.getElementById('activity-level').value; |
74 | 116 | const resultsDiv = document.getElementById('results'); |
75 | 117 |
|
76 | 118 | const height = parseFloat(heightInput); |
77 | 119 | const weight = parseFloat(weightInput); |
78 | 120 |
|
79 | | - if ( |
80 | | - isNaN(height) || |
81 | | - isNaN(weight) || |
82 | | - height <= 0 || |
83 | | - weight <= 0 |
84 | | - ) { |
| 121 | + if(isNaN(height) || isNaN(weight) || height <= 0 || weight <= 0) { |
85 | 122 | resultsDiv.textContent = 'Please enter valid positive numbers for height and weight.'; |
86 | 123 | return; |
87 | 124 | } |
88 | 125 |
|
89 | | - const heightInMeters = height / 100; |
90 | | - const bmi = weight / (heightInMeters * heightInMeters); |
91 | | - resultsDiv.textContent = `Your BMI is ${bmi.toFixed(2)}`; |
| 126 | + const heightM = height / 100; |
| 127 | + const bmi = weight / (heightM * heightM); |
| 128 | + const bmiFixed = bmi.toFixed(2); |
| 129 | + |
| 130 | + let category = ''; |
| 131 | + let mealPlan = ''; |
| 132 | + |
| 133 | + if(bmi < 18.6) { |
| 134 | + category = 'Underweight'; |
| 135 | + mealPlan = 'Include nutrient-rich foods such as whole grains, dairy, nuts, eggs, and lean meats. Eat small, frequent meals.'; |
| 136 | + } else if(bmi < 25) { |
| 137 | + category = 'Normal weight'; |
| 138 | + mealPlan = 'Maintain a balanced diet: mix of fruits, vegetables, whole grains, lean protein, and healthy fats. Practice portion control.'; |
| 139 | + } else { |
| 140 | + category = 'Overweight'; |
| 141 | + mealPlan = 'Prioritize vegetables, fruits, and whole grains. Limit processed foods, sugars, and saturated fats. Watch your meal portions.'; |
| 142 | + } |
| 143 | + |
| 144 | + if(category === 'Underweight' && activity === 'active') { |
| 145 | + mealPlan += ' You may consider adding muscle-building snacks like peanut butter smoothies.'; |
| 146 | + } else if(category === 'Overweight' && (activity === 'sedentary' || activity === 'light')) { |
| 147 | + mealPlan += ' Increasing your daily activity can further promote health and weight control.'; |
| 148 | + } |
| 149 | + |
| 150 | + resultsDiv.innerHTML = `<strong>Your BMI:</strong> ${bmiFixed}<br> |
| 151 | + <strong>Status:</strong> ${category}<br> |
| 152 | + <strong>Meal Recommendation:</strong> ${mealPlan}`; |
92 | 153 | }); |
93 | 154 | </script> |
94 | 155 | </body> |
|
0 commit comments