Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve() {
- const url = `https://judgetests.firebaseio.com/schedule/`; //имаше интервал в края!
- let lastId = 'depot';
- //let lastStop = "";
- let infoField = document.querySelector('#info span');
- let departButton = document.getElementById('depart');
- let arriveButton = document.getElementById('arrive');
- function depart() {
- let currUrl = `${url}${lastId}.json`;
- fetch(currUrl)
- .then(response => response.json())
- .then(response => infoField.textContent = `Next stop ${response.name}`)
- //lastStop = response.name; //не е нужно
- //lastId = response.next;
- //)
- .catch(() => {
- infoField.textContent = 'Error';
- departButton.disabled = true;
- arriveButton.disabled = true;
- });
- departButton.disabled = true;
- arriveButton.disabled = false;
- }
- function arrive() {
- fetch(`${url}${lastId}.json`)
- .then(response => response.json())
- .then(result => {
- infoField.textContent = `Arriving at ${result.name}`;
- lastId = result.next; //Тук вече трябва да се запази
- })
- .catch(() => {
- infoField.textContent = 'Error';
- departButton.disabled = true;
- arriveButton.disabled = true;
- });
- //infoField.textContent = `Arriving at ${lastStop}`;
- arriveButton.disabled = true;
- departButton.disabled = false;
- }
- return {
- depart,
- arrive
- };
- }
- let result = solve();
Add Comment
Please, Sign In to add comment