1import "./style.css";
2
3let count = 0;
4const counter = document.querySelector<HTMLButtonElement>("#counter")!;
5counter.addEventListener("click", () => {
6 counter.textContent = `count: ${++count}`;
7});
8
9const greeting = document.querySelector<HTMLElement>("#greeting")!;
10document
11 .querySelector("#load-greeting")!
12 .addEventListener("click", async () => {
13 try {
14 const response = await fetch("/example.json");
15 if (!response.ok) throw new Error(`HTTP ${response.status}`);
16 const body = (await response.json()) as { greeting: string };
17 greeting.textContent = body.greeting;
18 } catch {
19 greeting.textContent = "Could not load the greeting. Try again.";
20 }
21 });