Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // function solve() {
- // let infoElement = document.querySelector('#info span');
- // const departBtnElement = document.getElementById('depart');
- // const arriveBtnElement = document.getElementById('arrive');
- // let stopInfo = {
- // next: 'depot',
- // name: ''
- // };
- // function depart() {
- // infoElement.textContent = `Loading...`
- // departBtnElement.disabled = true;
- // const baseUrl = `http://localhost:3030/jsonstore/bus/schedule/${stopInfo.next}`
- // fetch(baseUrl).then(res => res.json()).then(result => {
- // stopInfo.next = result.next;
- // stopInfo.name = result.name;
- // infoElement.textContent = `Next stop ${result.name}`;
- // arriveBtnElement.disabled = false;
- // })
- // }
- // async function arrive() {
- // infoElement.textContent = `Arraving at ${stopInfo.name}`
- // departBtnElement.disabled = false;
- // arriveBtnElement.disabled = true;
- // }
- // return {
- // depart,
- // arrive
- // };
- // }
- // let result = solve();
- function solve() {
- let info = document.querySelector("#info span")
- let btnDepart = document.getElementById("depart")
- let btnArraival = document.getElementById("arrive")
- let ids = "depot"
- let currentStop = ""
- function depart() {
- // catching error and run function for present it
- let url = `http://localhost:3030/jsonstore/bus/schedule/${ids}`
- fetch (url)
- .then(response => response.json()) // convert response to json
- .then((data) =>{
- ids = data["next"]
- currentStop = data["name"]
- info.textContent = `Next stop ${data["name"]}`
- btnDepart.disabled = true;
- btnArraival.disabled = false;
- }) // function for present data
- .catch(() =>{
- info.textContent = "Error"
- btnDepart.disabled = true;
- btnArraival.disabled = true;
- })
- }
- async function arrive() {
- info.textContent = `Arriving at ${currentStop}`
- btnArraival.disabled = true;
- btnDepart.disabled = false;
- }
- return {
- depart,
- arrive
- };
- }
- let result = solve();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement