To change the page without a refresh, you ask Shopify for data with fetch. The cart lives at /cart.js. The data arrives later, so you give .then(...) a function to run when it's ready. It's always these three moves:
fetch("/cart.js") // 1. ask Shopify
.then(function (r) { return r.json(); }) // 2. response -> data
.then(function (cart) { // 3. now use the data
// cart.item_count, cart.items, cart.total_price ...
});
Don't memorize it. Learn the shape (ask, parse, use) so you can read it and catch it when it's wrong. The cart drawer reuses this exact chain next.
Stuck? The hints walk through it one line at a time. The last one shows the whole chain.