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 trialVytas .
971 PointsPlease help solve this challenge task. #array #.joinmethod
Use the array method that combines all of the items in an array into a single string. In the final string, the array items should be separated by a comma AND a space. Finally, log the final string value to the console.
var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
var mama = months.join(['December' = ', ']);
console.log(months);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
6 Answers
Vytas .
971 PointsI can't access last array item. ;/
Ryan B.
3,236 PointsHi Vytas try this and let me know. If it doesn't work i'll take another look at it for you.
var mama = months.join(', '); console.log(months[11]);
So, we created a variable 'mama' stored 'months' as the value and joined the string using .join(', '). Then we print to the console using 'console.log' we call on the months which holds your joined string and we add brackets. Those brackets represent the array that holds the months, which has a zero index. The zero index holds month 'January' the 3 index holds 'April' but we are looking for December which happens to be in the 11th index spot. We place 11 inside the brackets and we get our final answer.
Vytas .
971 PointsNo. Your solution either doesn't work. I tried this but still nothing.
var months = ['January','February','March','April','May','June','July','August','September','October','November','December']; var allMonths = months.indexOf(11); var allMonths2 = allMonths.join(', ');
console.log(allMonths2);
Vytas .
971 PointsNo. Your solution either doesn't work. I tried this but still nothing.
var months = ['January','February','March','April','May','June','July','August','September','October','November','December']; var allMonths = months.indexOf(11); var allMonths2 = allMonths.join(', ');
console.log(allMonths2);
Vytas .
971 PointsI almost sure that have to use indexOf method.
Vytas .
971 PointsI almost sure that have to use indexOf method.
Ryan B.
3,236 PointsVytas I apologize I thought too much into the question when I should have just went back to the challenge and looked at my solution. Heres what i did and it worked fine. Please forgive me I'm still learning.
var months =['January','February','March','April','May','June','July','August','September','October','November','December'];
var monthsString = months.join(', ');
console.log(monthsString);