Intermediate
Your own ValidationError
Finish the ValidationError class: it must extend Error, have the name ValidationError, and store which field was wrong.
Then write validateUsername(value): it trims the value and returns it if it is 3 to 15 characters long. Otherwise it throws new ValidationError("username", "...") with a helpful message. A value that isn't a string also throws a ValidationError.
What Check tests
ValidationErroris a kind ofError- Its name is
ValidationError - It keeps the field and the message
validateUsername(" asha ")returns"asha"- Too short or too long throws a ValidationError for
username - A non-string throws a ValidationError
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.