EXERCISE 6: User Profile - Input and Validation

Assignment

Create a user profile program that collects and validates user information:

  1. Ask the user for their first name using prompt()
  2. Ask the user for their age using prompt()
  3. Ask the user for their email address using prompt()
  4. Ask the user if they are a student (yes/no) using prompt()
  5. 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"
  6. Display a formatted profile using document.write() with all the information
  7. 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 typeof or isNaN() 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.