Advertisement
GalinaKG

Bus Stop

Feb 27th, 2023 (edited)
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getInfo() {
  2.  
  3.     const stopId = document.getElementById("stopId").value;
  4.     const url = `http://localhost:3030/jsonstore/bus/businfo/${stopId}`;
  5.    
  6.     const stopName = document.getElementById("stopName");
  7.     const buses = document.getElementById("buses");
  8.  
  9.     buses.replaceChildren();
  10.  
  11.  
  12.     fetch(url)
  13.         .then(data => data.json())
  14.         .then(data => {
  15.             stopName.textContent = '';
  16.             buses.textContent = '';
  17.             stopName.textContent = data.name;
  18.             Object.entries(data.buses).forEach(b => {
  19.                 const li = document.createElement('li');
  20.                 li.textContent = `Bus ${b[0]} arrives in ${b[1]} minutes`
  21.                 buses.appendChild(li);
  22.             })
  23.  
  24.         })  
  25.  
  26.         .catch(err => {stopName.textContent = 'Error'})
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement