-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
22 lines (18 loc) · 859 Bytes
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
document.getElementById('add-btn').addEventListener('click', function() {
// Get the input values
const ingredient = document.getElementById('ingredient').value;
const direction = document.getElementById('direction').value;
// Check if both fields are filled
if (ingredient === '' || direction === '') {
alert('Please fill in both the ingredient and the direction before adding.');
return; // Stop the function if any field is empty
}
// Create a new list item
const listItem = document.createElement('li');
listItem.textContent = `${ingredient}: ${direction}`;
// Append to the recipe list
document.getElementById('recipe-list').appendChild(listItem);
// Clear the input fields
document.getElementById('ingredient').value = '';
document.getElementById('direction').value = '';
});