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 trialnoel tanyanyiwa
6,877 PointsUse the array method that combines all of the items in an array into a single string. In the final string, the array i
task 1 of 1
var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>
2 Answers
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsHey friend noel tanyanyiwa , .join
is used to combine the items of an array into a single string.
Here is the whole code -
var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
console.log(months.join(', '));
It's been instructed in the question that the array items should be separated by a comma AND a space , so I've added a comma and a space , and then finally log the results
Hope this helps :)
Murilo de Melo
14,456 PointsIt's really weird how I interpret questions sometimes OR how the questions are formulated in the tutorials. For me, what is clear is that all items should be formed as a single String, except for the last one ('In the final string...'), which should be separated by comma.
JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovember, December.
Although, this does not make sense at all, it is what I understood from the question. Why wasn't it made less complicated, like "Display/print all the items separated by comma in a console". What I understand into a single String is 'one word'. At least if it were 'into single Strings', it would have made more sense.