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

Norman Fernandez
Norman Fernandez
11,804 Points

hey guy i need some help here i cannot understand what is my mistake?

someone can explain me my mistake, thanks for read me

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>

      var string=[1,2,3];
      function arrayCounter(string){
        if(typeof string== "undefined"){
          return 0;
        }
        else{
          return string.length;
        }
      };

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

2 Answers

Erik McClintock
Erik McClintock
45,783 Points

Norman,

Your conditional is incomplete. The challenge is asking you to make the arrayCounter function return 0 if the typeof the parameter passed in is a string, number, or undefined. Currently, you're only checking if the typeof the parameter is undefined. You need to include checks in that conditional (just use the OR operator [which is: || ] for simplicity) for the typeof your parameter being a string and a number, as well, and then you'll pass!

Erik

Norman Fernandez
Norman Fernandez
11,804 Points

thanks i did not know how to use the operator OR it was very helpfu.l