Intermediate
A sign-up form that explains its errors
When the form is submitted, stop the page from reloading and check the inputs with validateSignup(name, ageText):
- The name (after trimming) is required.
- The age must be a whole number from 1 to 120. Mention the word age in its error message.
If a check fails, validateSignup throws an error. Catch it in the submit handler and show err.message in #error, and empty #result.
If everything is valid, show Welcome, <name> (<age>) in #result, for example Welcome, Asha (12), and empty #error.
What Check tests
- An empty name shows an error
- Age
abcshows an error about the age - Age
200shows an error about the age - Age
4.5is rejected - Valid input shows
Welcome, Asha (12)and clears the error - No uncaught errors
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Your page
Press Run to see the page.
Console
Nothing logged yet.