Advertisement
EntropyStarRover

Rest 02. Bus schedule

Nov 8th, 2019
162
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.     let box = document.getElementById("info")
  4.     let dep = document.getElementById("depart");
  5.     let arr = document.getElementById("arrive");
  6.  
  7.     let currentId="depot";
  8.     let currentName="";
  9.  
  10.     function depart() {
  11.  
  12.       fetch(`https://judgetests.firebaseio.com/schedule/${currentId}.json`)
  13.       .then(res=>res.json())
  14.       .then(departSuccess)
  15.       .catch(err=>{ box.textContent="Error";
  16.       arr.disabled=true;
  17.       dep.disabled=true;
  18.     })
  19.     }
  20.  
  21.     function arrive() {
  22.         arr.disabled=true;
  23.         dep.disabled=false;
  24.         box.textContent=`Arriving at ${currentName}`
  25.     }
  26.  
  27.     function departSuccess(data){
  28.         let {name, next}=data;
  29.         currentId=next;
  30.         currentName=name;
  31.         dep.disabled=true;
  32.         arr.disabled=false;
  33.         box.textContent=`Next stop: ${currentName}`
  34.     }
  35.  
  36.     return {
  37.         depart,
  38.         arrive
  39.     };
  40. }
  41.  
  42. let result = solve();
Advertisement
RAW Paste Data Copied
Advertisement