antds/javascript-wonderland
0
1console.log('client side javascript file is loaded');2 3const weatherForm = document.querySelector('form');4const search = document.querySelector('input');5const messageOne = document.querySelector('#message-1');6const messageTwo = document.querySelector('#message-2');7 8weatherForm.addEventListener('submit', (e) => {9 e.preventDefault();10 const location = search.value;11 12 messageOne.textContent = 'Loading...';13 messageTwo.textContent = '';14 15 fetch('/weather?address=' + encodeURIComponent(location)).then((response) => {16 response.json().then((data) => {17 if (data.error) {18 messageOne.textContent = data.error;19 } else {20 messageOne.textContent = data.location;21 messageTwo.textContent = data.forecast;22 }23 });24 });25});