Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const form = document.getElementById('health-form');
+ const itemsList = document.getElementById('items-list');
+
+ form.addEventListener('submit', function(event) {
+ event.preventDefault();
+ const itemName = document.getElementById('item-name').value;
+ const itemDescription = document.getElementById('item-description').value;
+
+ const item = {
+ name: itemName,
+ description: itemDescription
+ };
+
+ logItem(item);
+ saveItemToCookie(item);
+ form.reset();
+ });
+
+ function logItem(item) {
+ const li = document.createElement('li');
+ li.textContent = `${item.name}: ${item.description}`;
+ itemsList.appendChild(li);
+ }
+
+ function saveItemToCookie(item) {
+ const items = getItemsFromCookie();
+ items.push(item);
+ document.cookie = `healthItems=${JSON.stringify(items)}; path=/`;
+ }
+
+ function getItemsFromCookie() {
+ const cookie = document.cookie.split('; ').find(row => row.startsWith('healthItems='));
+ return cookie ? JSON.parse(cookie.split('=')[1]) : [];
+ }
+
+ function loadItemsFromCookie() {
+ const items = getItemsFromCookie();
+ items.forEach(item => logItem(item));
+ }
+
+ loadItemsFromCookie();
+ });