Advertisement
Naralex

02. Bus Schedule

Jul 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     function solve() {
  2.  
  3.         let currentStop = '';
  4.         let nextStop = 'depot';
  5.  
  6.         function request(currentID){
  7.             let url = `https://judgetests.firebaseio.com/schedule/${currentID}.json `;
  8.             $.ajax({
  9.                 url,
  10.                 success,
  11.                 error
  12.             });
  13.         }
  14.         function depart(){
  15.             $('#depart').attr('disabled', true);
  16.             $('#arrive').attr('disabled', false);
  17.             request(nextStop);
  18.  
  19.         }
  20.         function arrive() {
  21.             $('#depart').attr('disabled', false);
  22.             $('#arrive').attr('disabled', true);
  23.             $('.info').text(`Arriving at ${currentStop}`);
  24.         }
  25.  
  26.         function success(res){
  27.             currentStop = res.name;
  28.             $('.info').text(`Next stop ${currentStop}`);
  29.             nextStop = res.next;
  30.         }
  31.         function error() {
  32.             $('.info').text('Error');
  33.             $('#depart').attr('disabled', true);
  34.             $('#arrive').attr('disabled', true);
  35.         }
  36.  
  37.         return {
  38.             depart,
  39.             arrive
  40.         };
  41.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement