-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
146 lines (129 loc) · 5.74 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Food Tracker</title>
<!-- Link to Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="new.css">
</head>
<body>
<header class="bg-primary text-white">
<div class="container">
<h1 class="display-4">Student Food Tracker</h1>
<nav>
<ul class="nav">
<li class="nav-item"><a class="nav-link" href="#">Home</a></li>
<li class="nav-item"><a class="nav-link" href="#">Track Food</a></li>
<li class="nav-item"><a class="nav-link" href="#">Budget</a></li>
<li class="nav-item"><a class="nav-link" href="#">Logout</a></li>
</ul>
</nav>
</div>
</header>
<
<main class="container mt-4">
<section class="food-entry">
<h2>Log Your Meal</h2>
<form>
<div class="form-group">
<label for="food-name">Food Name:</label>
<input type="text" class="form-control" id="food-name" name="food-name" required>
</div>
<div class="form-group">
<label for="calories">Calories:</label>
<input type="number" class="form-control" id="calories" name="calories" required>
</div>
<div class="form-group">
<label for="protein">Protein (g):</label>
<input type="number" class="form-control" id="protein" name="protein" required>
</div>
<div class="form-group">
<label for="carbs">Carbohydrates (g):</label>
<input type="number" class="form-control" id="carbs" name="carbs" required>
</div>
<div class="form-group">
<label for="fats">Fats (g):</label>
<input type="number" class="form-control" id="fats" name="fats" required>
</div>
<button type="submit" class="btn btn-primary">Add Entry</button>
</form>
</section>
<section class="food-list">
<h2>Meal Log</h2>
<ul class="list-group">
<!-- Example entry with a placeholder image -->
<li class="list-group-item">
<div class="row">
<div class="col-md-3">
<img src="placeholder.jpg" alt="Food Image" class="img-fluid rounded">
</div>
<div class="col-md-9">
<span class="food-name">Pizza</span>
<span class="calories">300 cal</span>
<span class="protein">12g</span>
<span class="carbs">30g</span>
<span class="fats">15g</span>
</div>
</div>
</li>
<!-- More entries can be added here -->
</ul>
</section>
<section class="budget mt-4">
<h2>Budget Tracker</h2>
<p>Your Budget: $<span id="budget">500</span></p>
<p>Remaining Budget: $<span id="remaining-budget">500</span></p>
</section>
</main>
<!-- Link to Bootstrap JS and jQuery -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
<script>
// Sample meal data (you can replace this with your database interactions)
const meals = [
{ name: "Pizza", calories: 300, protein: 12, carbs: 30, fats: 15 },
{ name: "Salad", calories: 150, protein: 5, carbs: 10, fats: 8 },
];
// Function to add a new meal entry
function addMeal() {
const foodName = document.getElementById("food-name").value;
const calories = parseFloat(document.getElementById("calories").value);
const protein = parseFloat(document.getElementById("protein").value);
const carbs = parseFloat(document.getElementById("carbs").value);
const fats = parseFloat(document.getElementById("fats").value);
// Add the new entry to the meal log
meals.push({ name: foodName, calories, protein, carbs, fats });
// Clear input fields
document.getElementById("food-name").value = "";
document.getElementById("calories").value = "";
document.getElementById("protein").value = "";
document.getElementById("carbs").value = "";
document.getElementById("fats").value = "";
// Refresh the meal log
displayMeals();
}
// Function to display meal entries
function displayMeals() {
const mealList = document.querySelector(".food-list ul");
mealList.innerHTML = "";
meals.forEach((meal) => {
const listItem = document.createElement("li");
listItem.innerHTML = `
<span class="food-name">${meal.name}</span>
<span class="calories">${meal.calories} cal</span>
<span class="protein">${meal.protein}g</span>
<span class="carbs">${meal.carbs}g</span>
<span class="fats">${meal.fats}g</span>
`;
mealList.appendChild(listItem);
});
}
// Call displayMeals to initially populate the meal log
displayMeals();
</script>
</html>