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 Foundations Functions Return Values

Return values stage 5

Can someone tell me what I am doing wrong here. I have been at this for a while and all I get is a parse error.

function arrayCounter (myArray) {
        if (typeof myArray ==== 'undefined', typeof myArray === 'string', typeof myArray === 'number')
        {

          return 0;
        }
       return myArray.length;
        }

2 Answers

Hi Jose,

You are very close. You need to remove the commas in the if conditional and replace them with a or statement (||). Commas in a if conditional have no meaning in javascript. Here is the code if you still need help.

function arrayCounter(myArray)
      {
        if (typeof myArray === 'string' || typeof myArray === 'number' || 
            typeof myArray === 'undefined')
        {
          return 0;
        }
        else
        {
            return myArray.length; 
        }
      }

Hope that helps.

Thank you Michael! I was going nuts trying to figure it out.

No Problem :)

Jason Montgomery
PLUS
Jason Montgomery
Courses Plus Student 2,277 Points

I have this for that same exercise.

function arrayCounter(myArray) { if (typeOf myArray === 'string' || typeOf myArray = 'number' || typeOf myArray === 'undefined') { return 0; } else { return myArray.length; } }

The terminal tells me it is a parse error of the syntax kind.