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

Javascript code challenge issue :(

QUESTION 2:

Create a method called 'requiredValues' that returns an array of all the values of inputs with the class of 'required'.

I need help with Task 2 ... can't get it to work.

My Code:

var $required = $(".required");
function requiredValues(){
   var blanks = new Array();
  $required.each(function(){
     blanks.push($(this).val() == "");
  });
    return blanks.indexOf(true);
}

3 Answers

I had the same problem until I realized that the challenge is asking you to return an array of all the values, not just the blank ones. If you take out the == "" from line 4 so that every value is being pushed and then return the array in line 7, it should work.

I got it working! Thank you Julianne =D I did return index of (true) instead of return array :D

Thanks a lot

You're welcome! Glad I could help. :)