Lesson 6 of 8
Read the whole form at once
- 12 min
- 5 checks
- 3 hints
- Go to task
Goal
Read every field in one line
Explanation
If you read a form field by field, the code grows with every new field, and you might forget the one that was added yesterday. new FormData(form) reads every field at once, and Object.fromEntries turns the result into a plain object, ready for JSON.stringify and for sending.
But FormData only sees fields that have a name. A field without one is dropped silently: no error, no warning, just a key missing from the request. And every value arrives as a string, so the quantity comes in as "2", not 2, and "2" + 1 gives "21".
A single input listener on the form covers all of its fields, because the event bubbles up to it from any field inside.
Your task
Write readForm(form) so it returns an object with every field and the quantity as a number, fix the field that gets dropped, then show JSON.stringify(readForm(form)) in #out on every edit.
Checks
5 checks- readForm reads the current values
- The email is in the output
- The quantity is a number, not a string
- A new field is read without changing the code
- The displayed output updates on every edit