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 trialSarah A. Morrigan
14,329 Pointswhere is array defined or input? this retuns Sintax errour
nowhere does array values are defined hence nothing can really happen
<!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
26,676 PointsHi 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.
-
array.length
is an invalid parameter name, names should only consist of a single word - your
IF
statements are missing the opening and closing parentheses - syntax such as
array.length === 'string'
as thelength
property is an int, to find the type of a variable you need to usetypeof
-
array.length()
is invalid sincelength
is a property, not a method -
return = 0;
is invalid asreturn
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!