Make Change

A Lustre web app in which you click coins (1, 5, 10, and 25) to make change for a random amount. The whole app is in src/make_change.gleam: a Model holds the goal and the coins chosen so far, each Message describes a click (Added, Undo, or Reset), update returns the new model for each message, and view turns the model into HTML.

Running It

Download make_change.zip from the link at the top of this page and unzip it. From inside the make_change folder, compile the Gleam code to JavaScript, then serve the folder with any static web server:

gleam build
python3 -m http.server

Then open http://localhost:8000. After you edit src/, run gleam build again and reload the page.

Creating It from Scratch

  1. Create a Gleam project that compiles to JavaScript:
    gleam new --template javascript make_change
    cd make_change
    
  2. Add Lustre:
    gleam add lustre
    
  3. Write the app in src/make_change.gleam. Its main function starts the Lustre app inside the page element with id app.
  4. Add index.html at the top level. It links the stylesheet make_change.css, has a <div id="app">, and imports main from the compiled JavaScript in build/dev/javascript/make_change/make_change.mjs and calls it.
  5. Add make_change.css at the top level to style the page (e.g., round coin buttons).

Back to Top

Accessibility Nondiscrimination

Copyright ยฉ2026, Regents of the University of California and respective authors.

This site is built following the Berkeley Class Site template, which is generously based on the Just the Class, and Just the Docs templates.

View all course offerings