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

Sarah A. Morrigan
Sarah A. Morrigan
14,329 Points

where is array defined or input? this retuns Sintax errour

nowhere does array values are defined hence nothing can really happen

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 (array.length) {
        if array.length === 'string' {
          return = 0;
        }
        if array.length === 'number' {
          return = 0;
        }
        if array.length === 'undefined' {
          return = 0;
        }
        return array.length();
      }


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

1 Answer

Chris Shaw
Chris Shaw
26,676 Points

Hi Sarah,

The parameter given to the arrayCounter function is passed through via the challenge validation, you don't need to specify this unless explicitly asked to by the challenge which isn't required in this case.

Some problems with your code are listed below.

  1. array.length is an invalid parameter name, names should only consist of a single word
  2. your IF statements are missing the opening and closing parentheses
  3. syntax such as array.length === 'string' as the length property is an int, to find the type of a variable you need to use typeof
  4. array.length() is invalid since length is a property, not a method
  5. return = 0; is invalid as return statements only require an expression.

The code you want to end up with should be similar to the below.

function arrayCounter(array) {
    if (typeof array === 'string' || typeof array === 'number' || typeof array === 'undefined') {
        return 0;
    }

    return array.length;
}

Happy coding!