Advertisement
Maxim_01

Untitled

Mar 24th, 2023
822
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 = "depot"
  4.  
  5.     let departBtn = document.getElementById("depart")
  6.     let arriveBtn = document.getElementById("arrive")
  7.     let infoSpan = document.querySelector("#info > span")
  8.     let currentStopName = null
  9.  
  10.     function depart() {
  11.         departBtn.disabled = true
  12.         arriveBtn.disabled = false
  13.  
  14.         fetch(`${BASE_URL}`)
  15.  
  16.         .then((res) => res.json())
  17.         .then((data) => {
  18.  
  19.             let currentStop = data[id]
  20.  
  21.             infoSpan.textContent = `Next stop ${currentStop.name}`
  22.             currentStopName = currentStop.name
  23.  
  24.             id = currentStop.next
  25.             currentStop = data[id]
  26.         })
  27.     }
  28.  
  29.     async function arrive() {
  30.         departBtn.disabled = false
  31.         arriveBtn.disabled = true
  32.         infoSpan.textContent = `Arriving at ${currentStopName}`
  33.     }
  34.  
  35.     return {
  36.         depart,
  37.         arrive
  38.     };
  39. }
  40.  
  41. let result = solve();
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement