Advertisement
GeorgiLukanov87

Bus-stop

Feb 27th, 2023
718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getInfo() {
  2.     const stopNameElement = document.getElementById('stopName');
  3.     const listNamesElement = document.getElementById('buses');
  4.     const stopIdElement = document.getElementById('stopId').value;
  5.    
  6.     stopNameElement.textContent = "Loading...";
  7.     const baseUrl = `http://localhost:3030/jsonstore/bus/businfo/${stopIdElement}`;
  8.  
  9.     fetch(baseUrl).then(res => res.json())
  10.         .then(result => {
  11.             listNamesElement.innerHTML = ''
  12.             stopNameElement.textContent = result.name;
  13.             for ([busId, arrivalTime] of Object.entries(result.buses)) {
  14.                 let newLi = document.createElement('li');
  15.                 newLi.textContent = `Bus ${busId} arrives in ${arrivalTime} minutes`
  16.                 listNamesElement.appendChild(newLi)
  17.             }
  18.         })
  19.         .catch(error => stopNameElement.textContent = 'Error');
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement