Assignment
Create a user profile program that collects and validates user information:
- Ask the user for their first name using
prompt() - Ask the user for their age using
prompt() - Ask the user for their email address using
prompt() - Ask the user if they are a student (yes/no) using
prompt() - Validate the inputs:
- Check if the name is not empty
- Check if the age is a valid number (convert using
Number()) - Check if the email contains an "@" symbol
- Check if the student response is "yes" or "no"
- Display a formatted profile using
document.write()with all the information - If any validation fails, display an appropriate error message
Requirements:
- Use
prompt()to get all user inputs - Use
Number()to convert the age to a number - Use
typeoforisNaN()to validate the age - Use conditional statements (if/else) for validation
- Use template literals (backticks) for string formatting in the output
- Display the profile in a clear, formatted way
- Use an external JavaScript file (script.js) linked to your HTML
Example Output:
If all validations pass, display something like:
User Profile:
Name: John Doe
Age: 25
Email: john@example.com
Student: Yes
Create an index.html file and a script.js file with your solution.