Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Foundations Functions Return Values

Nikki Turrisi
Nikki Turrisi
15,095 Points

I am struggling with this challenge question

I know my syntax is wrong, but I can't figure out why. I am stumped. Any help?

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 (1, 2, 3);
        return arrayCounter.length;
      console.log(arrayCounter);
        if(arrayCounter === 'undefined'); 
        return 0; 
      console.log(arrayCounter);

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

5 Answers

Jesus Mendoza
Jesus Mendoza
23,274 Points

Hi!

function arrayCounter (1, 2, 3) {
        return arrayCounter.length;
}
      console.log(arrayCounter);

if(arrayCounter === 'undefined') { 
        return 0;
}
      console.log(arrayCounter);

You're using semi-colons instead of curly brackets

B Nawaz
B Nawaz
13,402 Points

Indeed! Like Jesus said, you need to use curly braces for your function definition, as such:

function (param1, param2) { //outer curly braces //do some stuff

var curlyBracesUsed = true;

if (curlyBracesUsed) { //inner braces
     return "Then everything works!";
} //inner braces

} //outer curly braces

If this helped, mark me right, I want some of those sweet sweet forum points! :D

Varuzhan Darbinyan
Varuzhan Darbinyan
8,360 Points

This should work ;)

function arrayCounter(array) {
        if (typeof(array) === "string"){ 
          return 0;
        }
        else if (typeof(array) === "number") {
          return 0;
        }
        else if (typeof(array) === 'undefined') { 
          return 0;
        }
              else {
          return array.length;
          }
      }
Edmund lok
PLUS
Edmund lok
Courses Plus Student 6,465 Points

Hey maybe this will help!

<script> function arrayCounter (array) { if (typeof != 'object'){ return 0; } return array.length; } </script>

Edmund lok
PLUS
Edmund lok
Courses Plus Student 6,465 Points

Hey maybe this will help!

<script> function arrayCounter (array) { if (typeof != 'object'){ return 0; } return array.length; } </script>