Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMarlinda Davis
7,423 PointsAdding $username to form.
So I went ahead and added the username to the code so that it was required in order for the submit button to be active like Andrew suggested. Here's my code snapshot. https://w.trhou.se/l8h0omjsdm I am starting to feel like all this is making sense so I am pretty happy with myself. If I can make it better or add something to it please let me know (or if it doesn't work ._.; ). I am really enjoying this experience.
Edit: I posted this before I realized that the quiz at the end asked me to do the same thing. My code is a little different though so is it better to do it as the quiz suggested or is how I have it fine?
1 Answer
LaVaughn Haynes
12,397 PointsThe way you have it would technically allow the form to submit, but according to the challenge you would need to verify that the length of the username is greater than 0 using ".length > 0" the same way the password function is doing with ".length > 8".
In both cases the user could just type in a blank space for the username and that would allow the form to submit. Its not required but if you want one way to make it better you can verify that the username is actual text and not just a bunch of spaces. There are multiple ways to do that but one way would be to use the $.trim() function. It removes empty spaces from the beginning and end of a string.
var goodName = $.trim(" Marlinda ");
// goodName equals "Marlinda"
var badName = $.trim(" ");
//badName equals ""