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 trial

JavaScript jQuery Basics (2014) Creating a Password Confirmation Form Improving the form validation

Mark Bradshaw
PLUS
Mark Bradshaw
Courses Plus Student 7,658 Points

Stuck on a jquery quiz question.

Here's the task: On line 11 in app.js, implement the isUsernamePresent function. Return true if the username length is greater than 0.

Here's my code: My answer:

function isUsernamePresent() {
  if(isUsernamePresent().val().length > 0;)
}
Return true;

4 Answers

Hi Mark,

You have a few errors.

You used a capital 'R' for `return. You have also placed your return statement outside your function. You will need to get it back inside the closing curly brace.

You also have a misplaced semicolon at the end of your if condition and you don't want to call the function inside of itself.

You should use the $username variable which is storing the username input as pointed out by Michael.

function isUsernamePresent() {
  if ($username.val().length > 0) {
    return true;
  }
}

Also, whenever you have this pattern of, "if something is true, return true", you can just return that something directly. Making your code a little simpler.

function isUsernamePresent() {
  return $username.val().length > 0;
}
Mark Bradshaw
Mark Bradshaw
Courses Plus Student 7,658 Points

This clarification was exactly what I needed. Thanks.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

You have a capital R on your return keyword.

return is a specific keyword which isn't recognised if you capitalise it. :)

Michael Escoto
Michael Escoto
30,028 Points

I think the problem is you're calling the function name in the if statement.

Instead you'll need just use:

if($username.val().length > 0) 
Vittorio Somaschini
Vittorio Somaschini
33,371 Points

Yes Michael and Jonathan are both right Mark.

return needs to be all lowercase.

Also, the if condition should check the length of the value inside the $username variable (declared by the code at the beginning on line 5.

So $username.val().length is the right thing to do here