Welcome!
The last field is the age. It's a field for numbers (type="number"): when what's typed into it isn't a number, its value is empty text. And you remember that Number("") is 0, so check for an empty field first:
- When the age field is empty, show
Enter your age. - When the age is less than 13, show
You must be at least 13 years old.
When every field is right, the form has done its job. Remove it from the page, and show Welcome, Anna! in welcome, with the user name (trimmed) instead of Anna. An element is removed with its method remove():
form.remove();The element disappears from the page, with everything inside it.
That's the whole project. Your form checks what the user typed, field by field, with trim(), length, includes() and Number(). It shows what's wrong next to each field, empties the message once the field is right, and does its job only when everything is right. Real sign-up forms work like this too, and then the server checks everything once more, because anyone can change a script in their browser. In the next lesson, Timers and Waiting, your pages will learn to wait: to do something after a few seconds, or again and again, like a countdown.
Instructions
Check the age.
When every field is right, remove the form and welcome the user.