Project: Cargo Ledger
No new theory: this project uses everything from parts 1 and 2. Lists, boxes and layout, and scripts that read the page, count, loop, use functions and build elements. You build your own page from an empty folder: the ledger of the cargo bay, the list where every crate is written down.
This project is separate from the station site. When you're not sure how to do a step, open the lesson it comes from again.
Your files
The folder starts empty. Make three files with New file: index.html, style.css and script.js.
What you will see
The cargo master writes down every crate that comes on board, and she wants a page that does the sums for her. A finished ledger could show something like this:
Cargo Ledger
• Water: 120 kg
• Seeds: 15 kg
• Tools: 230 kg
• Medicine: 85 kg
Total: 450 kg in 4 crates
Average: 113 kg
[New crate]
The steps
Build it in this order:
- The frame.
index.htmlis in English and can show any letter. It is called Cargo Ledger on its tab and in its only biggest heading. - The crates. A list with the id
cargohas at least four crates. Each crate says what is inside, in aspanwith the classitem. It also has its weight in kilograms: only the number, in aspanwith the classweight. For example: Water: 120 kg. - The script. The head loads
script.js, and the script waits for the whole page. - The total. Under the list, a paragraph with the id
totalsays something likeTotal: 450 kg in 4 crates. It's worked out from the weights on the page. - The average. A paragraph with the id
averageshows the average weight, rounded to the nearest whole number:Average: 113 kg. - A new crate. A button with the id
new-cratesays New crate. It adds a crate ofSpare partsthat weighs25kg at the end of the list, built withcreateElement. The total and the average change with it. - A column. In
style.css, every element counts its border and padding in its width. The page sits in a column in the middle of the window, at most640pxwide. - A panel. The list is a panel of its own: a background the page doesn't have, space inside, a border and round corners.
- Easy to read, on a phone too. Everything is easy to read, and nothing comes out sideways on a phone.
Run the tests when you like. They tell you which steps are still missing.