MP2 showcase

Thursday, 10/22 · Week 8

Mini Project 2: Interactive Web Tool (repo URL) Due Wednesday, 10/21 Mini Project 2: Interactive Web Tool Due Thursday, 10/22 Checkpoint 4 Due Sunday, 10/25

Post-Class Notes

TL;DR#

Today we found the bug in the Spending Tracker's Delete button and saw the first half of the Mini Project 2 showcase, with questions from the room on every tool. The habit worth keeping: the page is drawn from the data, so a change goes to the array and the page is drawn again.

Before next class#

Checkpoint 4 is due Sunday 10/25.

  1. Mini Project 2. Open your live link in a private window, which shows it the way a first-time visitor sees it, with no saved data. If it shows a 404, follow the GitHub Pages guide.
  2. logs/wk08.md on GitHub by Sunday 10/25, as the weekly notes guide describes. A suggestion for this week: write down feedback you received or gave at the showcase, or an idea you took from another project, and what you would change in your own tool because of it.
  3. The Midterm Feedback Survey is due Sunday 10/25.

On Tuesday 10/27, the showcase will continue with everyone who has not presented yet, followed by the walkthrough questions.

The Delete button#

The playground is on slide 4 of today's slides. After Delete on Coffee, the list shows only Lunch, the total stays $17, and the Console shows that expenses still holds both items. li.remove() removes the list item from the page and leaves the array as it was. render() computes the total from the array, so the total cannot change.

The fix removes the item from the array and draws the page again:

deleteButton.addEventListener("click", () => {
  expenses.splice(expenses.indexOf(item), 1);
  render(expenses);
  console.log(expenses);
});

indexOf(item) finds the item's position in the array, and splice(position, 1) removes one element at that position. Replace li.remove(); in the playground with the first two lines and click Delete on Coffee: the total becomes $12 and the Console shows one object. splice is not in the arrays and loops slides. An agent will often use a method you have not met, and the Console is where you check what it did.

Every action that changes what the page shows follows the same pattern: change the array, then call render(). The Spending Tracker in the debugging slides has four more bugs to find.

Ideas from the showcase#
  • Try to break your own tool. A number field refuses letters but accepts e, because 1e9 is scientific notation for 1,000,000,000. Give the input a min and a max, and check the value in your JavaScript before you use it.
  • Explain any number you show. A score the user has not seen before needs its formula, in a line under it or behind a question-mark icon.
  • Show the end result first when a tool takes several steps, so the user knows what the steps lead to.
  • Decide what your tool does not do. One presenter declined a bill-splitting feature because it did not fit a tool for tracking expiry dates.
  • Use a small set of font sizes, and write them in DESIGN.md.
  • On a phone, every label takes space. Shorten labels or group them.
Your data in a private window#

localStorage keeps data in one browser on one computer, and it is still there after you close the tab or the browser. A private window starts with empty storage of its own, does not read the normal window's, and clears it when the last private window closes. That is why a tool opened in a private window shows no saved data, and why what you add there is gone once you close it.

APIs that need a key#

For Mini Project 3, start with an API that needs no key. A key in code that GitHub Pages serves can be read by anyone who opens the page's files. Mapbox, suggested in class for driving distances, needs an access token, so it is one of these. Thursday 10/29 will cover where a key goes.

Matching what someone types#

Suggesting matches from a list while the user types is called autocomplete, or typeahead. An <input> with a <datalist> gives a basic version with no JavaScript.