Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve() {
- const BASE_URL = "http://localhost:3030/jsonstore/bus/schedule/"
- let id = "2572"
- let departBtn = document.getElementById("depart")
- let arriveBtn = document.getElementById("arrive")
- let infoSpan = document.querySelector("#info > span")
- function depart() {
- departBtn.disabled = true
- arriveBtn.disabled = false
- fetch(`${BASE_URL}`)
- .then((res) => res.json())
- .then((data) => {
- let currentStop = data[id]
- id = currentStop.next
- currentStop = data[id]
- infoSpan.textContent = `Next stop ${currentStop.name}`
- })
- }
- async function arrive() {
- departBtn.disabled = false
- arriveBtn.disabled = true
- fetch(`${BASE_URL}${id}`)
- .then((res) => res.json())
- .then((data) => {
- let name = data.name
- infoSpan.textContent = `Arriving at ${name}`
- })
- }
- return {
- depart,
- arrive
- };
- }
- let result = solve();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement