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

Johnny Whitfield
Johnny Whitfield
14,024 Points

How am I "missing a function called 'arrayCounter'?"

I don't understand how I don't have the function arrayCounter when I started with function arrayCounter(). Please help me understand what I'm doing wrong.

index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>JavaScript Foundations: Functions</title>
    <style>
      html {
        background: #FAFAFA;
        font-family: sans-serif;
      }
    </style>
  </head>
  <body>
    <h1>JavaScript Foundations</h1>
    <h2>Functions: Return Values</h2>
    <script>

      function arrayCounter() {
        if (typeof arrayCounter == 'string', 'number', 'undefined'){
          arrayCounter = '0';}

        return arrayCounter.length;
      };      

    </script>
  </body>
</html>

1 Answer

Hey Johnny! The error message is a little misleading, since you obviously do have a function called arrayCounter. There are just a few things you need to change within your function to make it work properly.

First of all, your function is supposed to take in an array as a parameter (and then later return this array's length). Before you return the array's length, you will need to check to see if the type of the parameter being passed in is 'string', 'number' or 'undefined', and return 0 if it is. Your if condition is mostly correct, but keep in mind that to compare multiple things you will need to use the or operator: ||. For example:

if (a === b || a === d) {
  return 0;
}

Hope that helps!