Finding and changing elements, events, and loading data with fetch.
Print a cheat sheet (the whole course or one unit, with a picture of what each command draws)
document.querySelector('#go').addEventListener('click', function () {
what to do
});
When the element with id="go" is clicked, run the lines inside. # means id, as . means class.
id: on-click
document.querySelector('#message').textContent = 'Go!';
Replace the words inside the element with id="message".
id: change-the-text
const name = document.querySelector('#name').value;
Read what someone typed into the box with id="name".
id: read-a-box
const response = await fetch("weather.json");
const data = await response.json();
Example
<p id="out">Loading…</p>
<script>
async function load() {
const response = await fetch("weather.json");
const data = await response.json();
document.querySelector("#out").textContent = "Days: " + data.daily.time.length;
}
load();
</script>
Asks for a file or web address, waits for the reply, then turns it into data (objects and arrays). Both lines need await, inside an async function.

id: fetch-json
async function load() {
… await …
}
load();
A function that may wait for slow things with await. Call it like any function; the rest of the page keeps going while it waits.
id: async-function
try {
what might fail
} catch (error) {
plan B
}
Runs the lines in try; if one fails (no network, a blocked site), jumps to catch instead of stopping with an error.
id: try-and-catch