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 trialMichael Russell
7,332 PointsStuck on Code Challenge, Please help
Hi, I can't seem to figure this out but what I have seems like it should be the answer. The challenge is as follows: On line 11 in app.js, implement the is UsernamePresent function. Return true if the username length is greater than 0.
This is my failed solution:
function isUsernamePresent() {
return $username.val().length() > 0;
}
This was the only section of the code I was required to change for this challenge as far as I know.
Andrew McCormick
17,730 PointsI'm surprised that worked. I used your code just called length as a property and it worked fine:
function isUsernamePresent() { return $username.val().length > 0; }
Jason Anello
Courses Plus Student 94,610 PointsThat doesn't pass for me with the parenthesis. Without them it does. >= 1
would be the same as > 0
in this case.
Michael Russell
7,332 PointsI also tried using function isUsernamePresent() { return $username.length() > 0; }
with just the length as a property and it didn't work for me. I was getting frustrated and then I thought, hey '1' is more than '0', maybe it will work if I just set it greater or equal to '1', and that did the trick. Thank you for your time and help though, Andrew.
Michael Russell
7,332 PointsJason and Andrew, I understand now with my tired mind what you both are saying about length now and how it does not require the (). It would have probably worked the way I originally had it if I just removed the parenthesis. Thanks again.
Jason Anello
Courses Plus Student 94,610 PointsMichael,
The code that you are showing here has ()
after length
That's not using length as a property.
Michael Russell
7,332 PointsI know. I don't know how that one passed. It works just fine like this, which is probably the best solution like what you guys were saying:
return $username.val().length > 0;
Jason Anello
Courses Plus Student 94,610 PointsHi Michael,
Yes, you're correct. Your original code would have worked without the parenthesis.
This works:
return $username.val().length > 0;
This would also work too but probably less intuitive:
return $username.val().length >= 1;
Michael Russell
7,332 PointsIt passed with the "length( )" the first time. I copied and pasted the passing code in my answer. However, now when I try that 'answer', it doesn't pass and it shouldn't. I must have gotten lucky that one time.
10 Answers
Andrew McCormick
17,730 Pointslength is a property which does not accept parameters. You are calling it like it's a method.
Ary de Oliveira
28,298 PointsDry correct Answer
function isUsernamePresent() {
return $username.val().length > 0;
}
Rich Braymiller
7,119 PointsThis jqery course is almost unwatchable....the guy isn't clear at all, sorry but Treehouse needs to redo the jQuery course, off to code academy for jquery...
Ary de Oliveira
28,298 PointsOn Line 11. >= 1;
return $username.val().length >= 1;
Jason Anello
Courses Plus Student 94,610 PointsHi Michael,
length
is a property and not a method so you wouldn't use parenthesis with it.
Jason Anello
Courses Plus Student 94,610 PointsMichael Russell I appreciate you giving me best answer but to be fair, Andrew McCormick answered faster than I did and we both had essentially the same answer.
Michael Russell
7,332 PointsYou both had the best answer. I wasn't quite understanding what Andrew was talking about until you clarified it further. It didn't sink in until you chimed in. I thank you both very much for helping me to understand this concept a whole lot more.
Michael Russell
7,332 PointsNevermind, I figured it out and the following code did the trick: function isUsernamePresent() { return $username.val().length() >=1; }
It was a tricky question as it was asking for the username length to be "greater than 0".
Matthew Goodman
12,786 PointsOk I am stuck, function isUsernamePresent() { return $username.val().length()>0; }
Jason Anello
Courses Plus Student 94,610 PointsHi Matthew,
You have to remove the parentheses after length
length
is a property and not a method.
Matthew Goodman
12,786 Pointsok so it would just be
.length >0; as this don't work I think I am losing it.
Matthew Goodman
12,786 PointsMy bad, I had another } under the code thanks for the help Jason Anello it worked well.
sean mitchell
4,267 PointsSomething is going on with this challenge. First there is more than one way to write this code. But okay, lets play along and do it the way the instructor did, fair enough. I finally had to / figured out to copy the code from the hint function isPassorword or what ever, to PI$@@ at the moment to care, change it to $username and that worked. However the exact same code when typed in failed. But hey, I only tried like maybe thirty or forty times, with tabbing, spacing, with the keyboard upside down, etc so maybe I'm stupid and its me, right? How about put a #@$% skip button on this stuff so we can get on with it. 45 minutes of can't get it to work. And that is just for this one challange in this course. 1.5 hours lost total to stuff like this.
Jason Anello
Courses Plus Student 94,610 PointsHi Sean,
I'm not sure what's going on but I've tried again just now and I was able to type it in and pass task 1.
return $username.val().length > 0;
Michael Russell
7,332 PointsMichael Russell
7,332 PointsNevermind, I figured it out and the following code did the trick:
function isUsernamePresent() { return $username.val().length() >=1; }
It was a tricky question as it was asking for the username length to be "greater than 0".