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

Checking values challenge trouble

Hi, chaps!

I'm stuck with the Checking values challenge 2/3 step in the Building and interactive website course... can anyone help me?

this is what I answer :

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

31 Answers

Thanks for your answer Andrew.

I'll have to agree with other people who mentioned this stage was too big of a gap with the rest of the adventure. I think having a background in server side programming would help but most people doing the HTML/CSS courses don't. I worked a tiny bit with jQuery in the past and I was completely lost and this challenge.

Hi, Andrew, thanks for the quick response...

I understood what you've said, and I've tried again with this, but still don't get it:

var whatever = new Array ();

  function requiredValues(){
    $(".required").each({
        whatever.push($(this).val());
    })
}

I know I'm missing something, but just can't figure it out, even watching again and again the video. :-(

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi Alejandro,

At the end of the function you need to use the keyword return followed by the array variable.

In JavaScript the return keyword can be used at the end of a function to return a given value, a number, a string or in this case an array.

Hope this helps.

Regards Andrew

function isValidEmail(text){
    return text.indexOf("@") != -1;
}
var values = new Array();
function requiredValues(){
   $("input.required").each({
     values.push($(this).val())
  });
     return values();
 }

Bummer null.

function isValidEmail(text){
    return text.indexOf("@") != -1;
}
var values = new Array();
function requiredValues(){
  $("input.required").each({
    values.push($(this).val())
  });
    return values;
}

Also Bummer null. Copying without understanding, waiting for something to pass - that's where I'm at with this code challenge.

Please tell the development team "try to anticipate errors, and give better hints, as in the newest PHP videos".

function isValidEmail(text){
    return text.indexOf("@") != -1;
 }
var $required = $("input.required");
function requiredValues(){
  var values = new Array();
   $required.each(function(){
       values.push($(this).val());
  });
    return values;
}

This ended up working for me.

Hey @Alejandro :D sorry you're having trouble on this challenge! Could you link us to it and perhaps send a screenshot over to help@teamtreehouse.com ?

Screenshots will help us see what quiz or code challenge your on, what it is asking you exactly, what your answer is, and what the error message or hint says to you when it pops up. :)

I've reached out to Andrew about this for ya! The offices are closed for the weekend currently (7:03ish pm EST at the moment) so there might be a slight delay in getting back to you, just so you know ^^

Thanks, Andrew, I finally got it... :-)

now I'm stuck with the next code challenge, though.:-(

cant' pass the second part of the jQuery utility methods.

This is what I'm answering.

var values = $(".required").map(function(){
     return $(this).val();
});
    $.inArray(true, values) != "Andrew";

thanks for all your help!

Cheers!

I got stuck on this too. I keep rearranging lines in the function, I'm watching the video while I do this, and I still feel like I don't understand this at all.

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi John,

When there's a JavaScript syntax error it does the Bummer! null error, the development team are aware of this issue and are working on a solution to show the syntax error as the hint.

Hi Alejandro,

The inArray method returns a number or position of the element in the array.

So in your example tweaked $.inArray("Andrew", values) != -1 means if the string "Andrew" is not in the array values it'll return minus one and the not equals (!=) means it'll return true or false if present.

Thanks for your detailed reply, Andrew. JavaScript is definitely the chink in my front-end armor. It takes me a while to really see what you probably see instinctively. Glad you are on the team. :)

Matt Carr
Matt Carr
9,654 Points

The JavaScript/JQuery tutorials make me feel a little dumb. The difficulty of this challenge seemed to jump from the previous quizzes. I hope that if I just push through the videos it will come together in the end.

I'm having the same trouble even had to find this thread to do something..

JQuery and Validation form videos are not so easy to understand :/

But I guess it takes some time..

I was having issues with this challenge too. The 'wrong answer' messages I was getting simply stated that something was wrong with my code.

Nauman Ahmed
Nauman Ahmed
3,154 Points

Hi,

I am also stuck in the checking values challenge 3/3

Q: Create a method called 'containsBlanks' that returns true if any inputs with class 'required' has an empty string in, false if not.?

This is what i am doing. Please advise.

function containsBlanks() {
    $(".required").each(function(){
        $(this).val() == " "; 
    });
} 

Thanks.

Nauman Ahmed
Nauman Ahmed
3,154 Points

Is there anyone who can help me with my question above please?

Thanks.

Hi Nauman,

Try reading the responses from other Teachers and Students above! :) I've let our Teachers know you need help, but there might be a slight delay in getting back to you. Our offices are currently closed for the weekend. :) Mind sending me your work directly? Get in touch by emailing us at help@teamtreehouse.com. I'll get you connected with our Teachers.

Best,

Elizabeth

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi Nauman,

There's a couple of things missing

  1. You don't have an array to store the test you're performing i.e. $(this).val() == " ";
  2. You need to test if the array has a true in or not and return that on the last line of the containsBlanks function.
  3. " " is an a string with a space in it. An empty string looks like "".

Hope these pointers help.

Nauman Ahmed
Nauman Ahmed
3,154 Points

Hi,

Thanks for your reply. Just wanted to make sure we are on the same page. I am talking about the challenge number 3/3.

Q: is "Q: Create a method called 'containsBlanks' that returns true if any inputs with class 'required' has an empty string in, false if not.?"

I created the method called containsBlanks

//method called containsBlanks function containsBlanks() { //This line identifies the selector and creating anonymous function which gets the value of .required and returns the value of true or false? $(".required").each(function(){ $(this).val() == ""; }); } Do I return $(.required); at the end? I am still not sure what I am doing wrong... Sorry if my question doesnt make sense :-(

Nauman Ahmed
Nauman Ahmed
3,154 Points
//method called containsBlanks
function containsBlanks() { 
//This line identifies the selector and creating anonymous function which gets the value of .required and returns the value of true or false?
$(".required").each(function(){ 
$(this).val() == ""; 
}); }

Do I return $(.required); at the end? I am still not sure what I am doing wrong...

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher
function containsBlanks() { 
//Create an array here
$(".required").each(function(){ 
    $(this).val() == "";  //Put this value on to the array
}); 
//return true or false here depending on the contents of the array. I showed one what of doing it in the video.
}
Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher
function containsBlanks() { 
//Create an array here
$(".required").each(function(){ 
    $(this).val() == "";  //Push this value on to the array
}); 
//return true or false here depending on the contents of the array. I showed one what of doing it in the video.
}

Added some comments :)

Nauman Ahmed
Nauman Ahmed
3,154 Points

Thanks for your reply Andrew. I have added a new array and pushed the value on to the array. its still not working:(

$req = $(".required");
function containsBlanks(){
  var blanks = new Array(); // new array here
  $req.each(function() {
  blanks.push($(this).val() == "" ); // pushing the value on to the array
  });
  return blanks; // returning true or false
Nauman Ahmed
Nauman Ahmed
3,154 Points

ending curly bracket is also there after "return blanks;" I forgot to paste it in the code. sorry!

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

You're almost there Nauman.

So at the moment you have an array called blanks that contains trues and falses. So you need to figure out if the blanks array has a true in it.

Once you've figured that out then you can return true or false.

The previous video talks about 2 methods. One using indexOf which isn't cross-browser compatible and using another algorithm.

Nauman Ahmed
Nauman Ahmed
3,154 Points

Finally,

I used sort and pop method to return true OR false.

return.blank.sort().pop();

It worked :-) Thanks for all your help........

Thanks.

I have the following and I get this error: Oops! It looks like Task 1 is no longer passing. (Even though, I haven't touched the first function), can anybody help with this ?

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


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

};

var $required = $(".required");
function containsBlanks(){
var blanks = new Array();
  $required.each(function(){
    blanks.push($(this).val() == "" );                
                 };)
  return blanks.sort().pop();
};

I managed to finish the challenge with the code above but I've got not idea what's the difference between mine and his (except for the variable having a different name) ?

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

I get an SyntaxError: Unexpected token ; with the code you posted above Charlie. Is suspect it was this };) here should have been });. Putting a semi-colon before a ) like that will terminate the line and that ) is just dangling there.

If previous steps fail in a code challenge it's often due to a syntactical mistake. I know the app team are working on making the error hints better but in the mean time keep an eye out for syntax issues for tasks that no longer pass.

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Thanks for the feedback.

We'll be working on narrowing that gap with upcoming content releases.

Keep an eye out on our roadmap as things progress.

Maximiliane Quel
PLUS
Maximiliane Quel
Courses Plus Student 55,489 Points

I'd like to join the others in saying that this code challenge has been impossibly difficult. And while it took ages to figure out what was supposed to happen in step two, I spend even more time trying to figure out how to employ the code of step two in step three. Is that possible? Where we supposed to try that? Otherwise, why are we returning the values of of the required fields or is that just a proof of concept? I am still confused.

Jon Edwards
Jon Edwards
7,913 Points

I ran across this thread searching for help on this same code challenge.

I agree its complicated but that's how it is with programming from what I can tell. More important to understand what they are doing and why, then just follow along in the code copying what they type. Over time the syntax becomes more apparent, and can always be debugged!

When I have trouble I rewatch each video and listen as he describes each step, then slowly it starts to make sense, each code challenge uses the same techniques he describes. Good Luck!

(I realize this is an old thread but many will come across this looking for help!)

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

Hi Alejandro,

The question is:

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

Not if they contain blanks or not :)

Let me know how you get on!

Regards

Andrew