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

Joseph Knoll
Joseph Knoll
20,481 Points

"Checking Values" video and the use of IndexOf

I noticed that you avoided the use of the "IndexOf" method to check for 'true' values in the array 'blanks', which stored the boolean values for the check on the required fields to see if they were empty. As you stated, this was due to old browser functionality (or the lack of it) when it comes to 'IndexOf'.

However, when you were doing the simple check of the email validity with the presence of the '@', you did use the IndexOf method. I can see that the same fix would not work because you wouldn't be able to use the sort method in the same way, but wouldn't you still have the same issues with old browsers? If so, why would you fix a portion of the code and not the other? Also, what would be a good fix for the email validation without the use of IndexOf? (Assuming you are just using that simple check for '@')

POST SCRIPT:

Of course the second part of my question was answered in the next video using the inArray() utility. I assume that the first question about fixing only a portion of the code was that we hadn't learned this yet. ;)

4 Answers

Nick Pettit
STAFF
Nick Pettit
Treehouse Teacher

Hi Joseph Knoll,

Sorry for the slow reply. Which language are you talking about? Is this in our JavaScript, Ruby, or PHP videos?

Once we figure that out, we can tag it appropriately so that a teacher can find your post. :)

Nick

Joseph Knoll
Joseph Knoll
20,481 Points

Hey Nick,

Thanks for the reply. This was in the jquery section I believe, sorry I didn't tag it well, I am new to the forum and asking questions (new to the site in general). I think my questions were answered in next few videos that followed.

I have to say that I love what you guys are doing, and I am burning through your videos at a rapid pace. I hope that I can retain this stuff and be able to recall and use it in practical application. I'm rediscovering that I have a real passion for some of this material.

Regards,

Joe

Nick Pettit
STAFF
Nick Pettit
Treehouse Teacher

That's great to hear! Glad you're enjoying the material.

Andrew Chalkley teaches our jQuery material, so he should be able to answer your questions.

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Arrays and Strings are different object types so the methods and implementations are different.

When using indexOf in a String is fine as this is implemented already in older browsers in JavaScript 1.0/ECMAScript 1st Edition so all implementations should have it, whereas the Array was implemented in JavaScript 1.6/ECMAScript 5th Edition. inArray fixes the Array usage in older (and newer) browsers.

As for making the eMail more robust we use a plugin that uses a regular expression which is pretty crazy territory to take a diversion in to. You can take a look at the Gold workshop on creating the plugin here or check the source code here.