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

Part 3/3 of Checking Values Code Challenge

Hi,

I'm fairly certain I am putting in valid code for the third step of the checking values code challenge for checking if there are blanks in the array.

My code works when I run it in Coda but not when I run it in the treehouse challenge page. This code challenge seems arbitrary since there are so many ways of doing this.

Here is my code:

function containsBlanks() {

        var myArray = [];

        if ($.inArray("", myArray)) {


            return true;

             } else {

            return false;

        }


};

I keep getting an error message from the treehouse site saying something is wrong with my code. Help please!

Thanks,

Calvin

5 Answers

Meg Cusack
Meg Cusack
11,448 Points

I am lost here- first time in all of the Treehouse training videos. I've watched the video Checking Values three times and took detailed notes but still lost. He seemed to move really fast. I figured out challenge 3/1 but none of the others. Just a FYI about it as it looks like others are struggling too. I will move onto another area instead and try to do some side training to equip me more for this level later on. Love the training videos and challenges overall though!

The Challenge title is "Create a method called 'containsBlanks' that returns true if the array has any blanks in it, false if not."

and the error message I am getting is "Bummer! There is something wrong with your code in your 'containsBlanks' function."

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

The inArray() method returns an integer or number. Here's a link to the jQuery docs.

It returns a zero-based index so if -1 is returned that means it doesn't contain the string your searching for.

Does that help?

I had already read the jQuery docs for inArray(). I can't say that your answer is that helpful.

I had tried:

function containsBlanks() {

        var myArray = [];

        var result = $.inArray("", myArray);

        if (result != -1) {


            return true;

             } else {

            return false;

        }


};

But this didn't work either. Still having trouble figuring this out. Starting to think that there are some fundamental issues with the way jQuery is being taught on treehouse.

Learning jQuery third edition seems to have a much more reasonable pace and learning path.

Andrew Chalkley
STAFF
Andrew Chalkley
Treehouse Guest Teacher

You're almost there Calvin.

You're testing an array myArray rather than the array from the previous steps. Once you've changed that you're good :)