WEBT Logs
Well-formed means the tags follow XML's structural grammar — properly nested, one root, every start-tag closed — so any parser can read it without choking.
XML lets you invent tag names, but it is strict about how you write them. A document that breaks these rules is rejected out...
Q How does the Open Transport API /stationboard endpoint work, and how do station, id, and limit inter...
/stationboard returns the next connections leaving a given station — you identify the station by name or by id, and limit caps how many departures come back.
This is the display step: once the user picked a station, you fetch its upcoming departures.
http://transport.opendata.ch/...
Q How do you turn a JSON API response into rendered HTML rows in the DOM?
You loop over the response array, build up one HTML string of <tr> rows, and assign that string to the table body's innerHTML in a single step.
The pattern is "accumulate a string, then inject once". Looping and writing each row to the DOM individually would be slow; building one...
Q What is XML and what is its basic structure?
XML (Extensible Markup Language) is a text format that encodes structured data as a tree of nested, freely-named tags.
Every piece of data sits inside an element, written with a matching start- and end-tag: <name>Anna</name>. Elements nest inside other elements, so the whole docu...
Q What value types does JSON support, and what notable type is missing?
JSON has six value types — string, number, boolean, null, array, object — and crucially has no date type.
{
"string": "hello",
"number": 42,
"float": 3.14,
"boolean": true,
"nothing": null,
"array": [1, 2, 3],
"object": { "nested": "value" }
}
* Six value types —...
Q How do you implement a type-ahead (autocomplete) station search with AJAX?
On each keystroke, JavaScript fires an AJAX call to /locations with the text typed so far, then shows the returned matches in a dropdown for the user to pick from.
AJAX just means making an HTTP request from JavaScript in the background and updating the page with the result — no...
Q How do you compute and display a train's delay from the transport API's response?
You subtract the scheduled departure time from the API's predicted ("prognosis") time and convert that millisecond difference into minutes.
The API gives two timestamps per departure, and the delay is simply the gap between them:
stop.departure — the scheduled time.
stop.prognos...
Q What is JSON and why is it popular for web APIs?
JSON (JavaScript Object Notation) is a lightweight text format whose syntax mirrors JavaScript objects, so the browser can turn it into usable data almost for free.
JSON encodes data as key–value pairs inside { }, looking just like a JavaScript object literal:
{
"name": "Anna M...
Q What are the key differences between XML and JSON, and which is preferred for web APIs?
JSON is compact and maps straight onto JavaScript data, while XML is more verbose but supports attributes, comments, and richer schema validation — and for web APIs, JSON usually wins.
The same data shows the contrast. In XML a list of relatives needs a repeated tag for each item...
Q When fetching a stationboard, why wrap the call in try…catch and check response.ok separately?
Because fetch only rejects on network failure, not on HTTP error statuses — so you need both: try…catch for the network, and an explicit response.ok check for 4xx/5xx responses.
* fetch's two failure classes: the network rejects into catch; HTTP errors resolve and need the respo...