Use your DOM and events knowledge to build a form validator that checks user input in real-time and shows helpful error messages — just like real login forms on the web.
YOUR TASK
Create a validateForm(data) function that:
Accepts an object with name, email, and password fields
Checks name: must not be empty, must be at least 2 characters
Checks email: must contain @ and a . after the @
Checks password: must be at least 8 characters long
Collects all errors into an array and logs them one by one
If no errors: logs "Form is valid! Submitting..."
Test it with both valid and invalid inputs to confirm all error messages fire correctly.
Need a hint?
Structure to follow:
1. function validateForm(data) {'{'}
2. const errors = [];
3. Check each field, push errors: errors.push("Name is required")
4. Email check: !data.email.includes('@') || !data.email.split('@')[1].includes('.')
5. Password: data.password.length < 8
6. if (errors.length) {'{'} errors.forEach(e => console.log(e)); {'}'}
7. else {'{'} console.log("Form is valid! Submitting..."); {'}'}
8. Test with a bad object then a good one
Example output (invalid then valid):
--- Invalid ---
Name must be at least 2 characters
Invalid email address
Password must be at least 8 characters
--- Valid ---
Form is valid! Submitting...
Code Editor Ready
Output
Console
Console initialized...
Ready for Project 4: Form Validator
> Build your validation logic and test with valid + invalid inputs
> Hit "Check My Code" when ready!