Advertisement
Maxim_01

Untitled

Mar 24th, 2023
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     const BASE_URL = "http://localhost:3030/jsonstore/bus/schedule/"
  3.     let id = "2572"
  4.  
  5.     let departBtn = document.getElementById("depart")
  6.     let arriveBtn = document.getElementById("arrive")
  7.     let infoSpan = document.querySelector("#info > span")
  8.  
  9.     function depart() {
  10.         departBtn.disabled = true
  11.         arriveBtn.disabled = false
  12.  
  13.         fetch(`${BASE_URL}`)
  14.  
  15.         .then((res) => res.json())
  16.         .then((data) => {
  17.  
  18.             let currentStop = data[id]
  19.             id = currentStop.next
  20.             currentStop = data[id]
  21.  
  22.            
  23.             infoSpan.textContent = `Next stop ${currentStop.name}`
  24.         })
  25.  
  26.  
  27.     }
  28.  
  29.     async function arrive() {
  30.         departBtn.disabled = false
  31.         arriveBtn.disabled = true
  32.  
  33.         fetch(`${BASE_URL}${id}`)
  34.         .then((res) => res.json())
  35.         .then((data) => {
  36.  
  37.             let name = data.name
  38.             infoSpan.textContent = `Arriving at ${name}`
  39.  
  40.  
  41.         })
  42.  
  43.  
  44.  
  45.     }
  46.  
  47.     return {
  48.         depart,
  49.         arrive
  50.     };
  51. }
  52.  
  53. let result = solve();
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement