Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve() {
- let info=document.getElementById("info");
- let nextStopId="depot";
- let departBtn=document.getElementById("depart");
- let arrivebtn=document.getElementById("arrive");
- let curentStopName="Depot";
- function fetchNext(nextStopId){
- var requestOptions = {
- method: 'GET',
- redirect: 'follow'
- };
- fetch(`http://localhost:3030/jsonstore/bus/schedule/${nextStopId}`, requestOptions)
- .then(response => response.text())
- .then(r =>JSON.parse(r))
- .then(r=>update(r))
- .catch(error => kill());
- }
- function depart() {
- fetchNext(nextStopId);
- departBtn.disabled=true;
- arrivebtn.disabled=false;
- }
- function arrive() {
- info.textContent=`Arriving at ${curentStopName}`
- departBtn.disabled=false;
- arrivebtn.disabled=true;
- }
- function update(obj){
- info.textContent=`Next stop ${obj.name}`;
- curentStopName=obj.name;
- nextStopId=obj.next;
- }
- function kill(){
- departBtn.disabled=true;
- arrivebtn.disabled=true;
- info.textContent="Error"
- }
- return {
- depart,
- arrive
- };
- }
- let result = solve();
Add Comment
Please, Sign In to add comment