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

Help on Code Challenge: Simple Email Validation Plugin 2/4

Question: Open a new script tag and using the "validEmail" plugin, store in a variable "isValid" whether the email address in the text input is valid.

I Put: <script> var isValid = $("input").validEmail(); var isValid: true </script>

Can someone please tell me what I am doing wrong and how I can fix it? Thanks in advance!

2 Answers

Hi Alyssa

You are pretty much there!

You don't need to put var isValid: true since the actual plugin returns a true or false value so the first part of your script is it! :)

ps. were you trying to set isValid to true with var isValid: true ?

Yes, but I was a bit confused on how to do this challenge to start with. Thanks for your help; it worked!

The challenge only wants you to set the variable. The Boolean part is already taken care of because validEmail() returns a Boolean(0/1, false/true). Moreover it seems like you were calling the method into the var isValid and then trying to format it to a Boolean true, at least I think that's your interpretation. If it is, I see where your coming from. You don't have to say what type of variable it is(unlike for example java where to declare a Boolean you would have to type

bool isValid; //isValid will be either 0 or 1
isValid = /*Some Method*/ ;

In this challenge you had to pass parameters to validEmail with an options Array.

var options = {on: "", success:"", failure:""}

And if that was where you are getting lost the difference between having to declare what failure, success, etc are and having to declare a variable is similar to css(I assume you have some understanding of it). In css there are a bunch of attributes you can set and if you do not want to set all of them and only declare the ones you want then you have to specify which ones your going to change because for every selector you're going to be using different attributes. Likewise in this validEmail you are using on, success, failure, however maybe later you will use totally different parameters so to make sure the computer knows which ones your using you have to use the key: value method, unlike a variable where the computer can figure it out by itself. Make sense or am I totally on a tangent and confused you more(I hope not)?