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 trialWilliam MacNish
11,709 PointsCoded a map function that doesn't generate commas, why?
I wrote alternate code for the generateOptions() function, and it doesn't produce commas. Why is that?
function generateOptions(data) {
data.map( (entry) => {
select.innerHTML += <option value="${entry}">${entry}</option>
;
});
}
1 Answer
Travis Alstrand
Treehouse Project ReviewerHey William MacNish !
In JavaScript, Array.map()
is used to transform each element of an array and return a new array.
In your code, you're not using the returned array but instead appending directly to innerHTML. This means that no automatic separators (like commas) are added between the options.
If you're wanting commas in your select.innerHTML
, you'll need to manually add them, but I'm not 100% sure of why / where you're wanting or expecting commas here.
I hope this helps and makes sense, if not, or if you'd like to explain where you're wanting commas feel free to reply