Make Change
- Download: make_change.zip
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
- Create a Gleam project that compiles to JavaScript:
gleam new --template javascript make_change cd make_change - Add Lustre:
gleam add lustre - Write the app in
src/make_change.gleam. Itsmainfunction starts the Lustre app inside the page element with idapp. - Add
index.htmlat the top level. It links the stylesheetmake_change.css, has a<div id="app">, and importsmainfrom the compiled JavaScript inbuild/dev/javascript/make_change/make_change.mjsand calls it. - Add
make_change.cssat the top level to style the page (e.g., round coin buttons).