function checkSubmissionValid(event) { let message = document.querySelector('textarea[name="message"]').value; let github = document.querySelector('input[name="github"]').value; if (message.length < 1 || github.length < 1) { event.preventDefault(); document.querySelector('.status').textContent = "Fill out all fields"; } else { document.querySelector('.status').textContent = "Post succesful!"; } } fetch('https://guestbook-api.hnasheralneam.dev/messages/random-5') .then(response => response.json()) .then(data => { for (let i = 0; i < data.length; i++) { createMessage(data[i]); } }) .catch(error => { console.error('Error fetching data:', error); }); function getAll() { document.querySelector('.messages').innerHTML = ""; fetch('https://guestbook-api.hnasheralneam.dev/messages/all') .then(response => response.json()) .then(data => { for (let i = 0; i < data.length; i++) { createMessage(data[i]); } }) .catch(error => { console.error('Error fetching data:', error); }); } function createMessage(message) { const messageDiv = document.createElement('div'); messageDiv.classList.add('card'); messageDiv.innerHTML = `