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

Form Validation and Manipulation- Checking Values

I'm stuck on the first code challenge. I've re watched the video several times, but know that I'm missing something.

The code challenge is asking me to "Create a method called 'isValidEmail' that takes one argument that returns true when a string with an '@' symbol is passed, false if not."

The only thing I can think to come up with is:

function isVaildEmail(email){ return email.indexOf("@") !=-1;

};

It's telling me I'm not defining the function of "isValidEmail." I know I haven't defined it, but how do I define the function at the same time returns true?

I apologize in advance if this is easy to some, I'm just very lost at the moment.

8 Answers

I'm equally lost on this code challenge. I'm glad you figured it out, and I will copy-past the code. But that is missing the point of doing a course isn't it. I have to say this jQuery section is almost a bridge too far. Up till now the video lessons and challenges have been a steady increase of knowledge. Here the gradient has leapt forward, to the point where it is nearly impossible.

I agree with you Jen & Jamil- the questions now need to be figured out ( which makes it hard when tons of new concepts are being introduced and no opportunity to practice them) up to this point all of the questions were code we've already written and had fully explained ( and in a language( HTML,CSS) more straight forward than javaScript). This section is making me doubt my awesome abilities and making this course very frustrating.

Hey Jen. I completely agree with your first comment. I am a complete newbie at ALL computer code but I have managed to slowly grasp concepts and learn on the way. All up until I got to this Jquery section. It's just jumping ahead by leaps and bounds before I even grasp the information.

Jamil, I started this free course on jQuery which is actually excellent: http://try.jquery.com/. When I finish that I;ll come back and complete this one

Good call with the try.jquery.com training. I just finished last night and it helped a great deal. Thanks!

I solved it!

I entered in:

var $isValidEmail = $(".required input");

function containsBlanks(){ }

function isValidEmail(email){ return email.indexOf("@") !=-1;

}

Just out of curiosity, is the "function containsBlanks(){}" necessary for the return true when the string is passed??

Can anyone explain why the !=-1 works to validate the email? So what if it's not -1? How does that validate anything? And how does the computer compute this?

Can anyone explain why the !=-1 works to validate the email? So what if it's not -1? How does that validate anything? And how does the computer compute this?

Jen the != means "not equal to" whenever the code does not find a "@" on the input the result would be -1 so, validate as true if the string number is any number except -1.