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

Jacob Roman
Jacob Roman
22,640 Points

Checking Values Code Challenge

I have been trying to figure out what I am doing wrong for the Forms and Validation - Checking Values Video.

Below is the code I have input and it says that something is wrong with my requiredValues function. I am not that great with Javascript. Any help would be great so I can comeplete this quiz.

Thanks in advanced.

var $required = $(".required");
function requiredValues(){
    var blanks = new Array();
  $required.each(function(){
    blanks.push($(this).val() == "");
  });
  return blanks.sort().pop();
}
function isValidEmail(email) {
    return email.indexOf("@") != -1;
}

4 Answers

Joseph Siddiq
PLUS
Joseph Siddiq
Courses Plus Student 7,133 Points

Hey Jacob - The challenge (task 2 of 3, just to make sure) is looking for narrower response than the functions described in the video, I was doing the same as above but the below worked out for me. Rather than testing the returned value, all you need to do is just return an array with all the values of the inputs.

The below worked for me, 'values' represents an array populated by the values of each of the inputs with the class required. Then you just return the array.

Let me know if I'm overlooking something.

var requiredValues = function(){
    var values = new Array();
  $(".required").each(function(){
    values.push($(this).val());
  });
  return values;
};
Jacob Roman
Jacob Roman
22,640 Points

Thanks for the response. I actually just got my answer from this post right before you posted. haha.

Jessica Barnett
Jessica Barnett
8,028 Points

Thanks for this post! I was having a very similar problem and you helped me out too. yay.

Armand Ramirez
Armand Ramirez
4,016 Points

Interesting, I was having a similar problem.

This code wasn't passing:

function requiredValues(){
  var tArray = new Array();

  $(".required input").each(function(){
   tArray.push($(this).val());
  })
  return tArray;
}

I changed the selector to $('.required') and the code passed, even though $('.required input') is actually selecting the same element, no?