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
barak ben ishay
1,951 Pointsarray with for loop , No spaces between
<script> var names = ['barak', 'dianna'];
for (var i = 0; i < names.length; i+=1) { document.write ( names[i]); }; </script>
it print the names without spaces or commas, why and how to fix it so it will print as it should. thanke you!
2 Answers
Steven Parker
243,356 PointsYou didn't provide a link to the course page, so it's not clear what "as it should" would be. But here's one way to separate the list items with a space and comma:
for (var i = 0; i < names.length; i += 1) {
if (i > 0) document.write(", "); // add separators before all but the first
document.write(names[i]);
}
barak ben ishay
1,951 Pointshaa .. ok , but isnt takes it around, you canot do anything else?
Steven Parker
243,356 PointsI'm not sure what you mean by "isnt takes it around". What is the "anything else" you would rather do?
If this relates to something on a course page, it would help to provide a link to that page.