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 Loops, Arrays and Objects Tracking Multiple Items with Arrays Using Array Methods

analyn jane calado
analyn jane calado
3,523 Points

don't know whats missing

can't figure out the final answer.

script.js
var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
var AND = function(monthsOftheYear) { 
months.indexOf(monthsOftheYear);
};

console.log(AND('december'));
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

4 Answers

Tiffany McAllister
Tiffany McAllister
25,806 Points

You need to use the join() method on the array to join the items together into a single string. You then have to pass a comma and a space to the method as this lets the method know how you want the items to be separated.

var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];

var monthsJoined = months.join(', ');

console.log(monthsJoined);
Chase Swanson
PLUS
Chase Swanson
Courses Plus Student 8,886 Points

I think you may just be misinterpreting the objective.

You want to call a method on the array "months" that will join all the items in the array together with a comma and a space. When you send it to the console it should look like....

"January, February, March, April, May, June, ..., December"

Hopefully that points you in the right direction without divulging the answer.

Chase

Benjamin Leichter
Benjamin Leichter
7,968 Points

^^^ Stole the words right out of my mouth, Tiffany!

Alternatively, you could do this:

months = months.join(", ");
console.log(months);
Chase Swanson
PLUS
Chase Swanson
Courses Plus Student 8,886 Points

Both Tiffany and Ben are correct.

I would encourage you not to give the answers though, rather help guide people to the answer.

It is a learning site.

analyn jane calado
analyn jane calado
3,523 Points

yeah.. your right chase. hmm i looked at your comment first, and i answered it! then, Tiffany and Ben followed an answer. but I'm already done at my work spaces.