Advertisement
osman1997

Untitled

Jul 7th, 2021
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. function solve() {
  2.  
  3. let baseUrl = 'http://localhost:3030/jsonstore/bus/schedule/';
  4. let firstStop = 'depot';
  5. let textArea = document.getElementById('info');
  6.  
  7. let departButton = document.getElementById('depart');
  8. let arriveButton = document.getElementById('arrive');
  9.  
  10. function depart() {
  11. departButton.disabled = true;
  12. arriveButton.disabled = false;
  13.  
  14. fetch(`${baseUrl}${firstStop}`)
  15. .then(res => res.json())
  16. .then(response => {
  17. textArea.textContent = `Next stop ${response.name}`;
  18. });
  19. }
  20.  
  21. function arrive() {
  22. departButton.disabled = false;
  23. arriveButton.disabled = true;
  24.  
  25. fetch(`${baseUrl}${firstStop}`)
  26. .then(res => res.json())
  27. .then(response => {
  28. textArea.textContent = `Arriving at ${response.name}`;
  29. firstStop = response.next;
  30. });
  31.  
  32.  
  33. }
  34.  
  35. return {
  36. depart,
  37. arrive
  38. };
  39. }
  40.  
  41. let result = solve();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement