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 Array Iteration with a For Loop

Mike Hatch
Mike Hatch
14,940 Points

Using a Template Literal?

Exercise 2 | Step 3

Would there be any reason not to use a template literal for the solution? My solution is only slightly DRYer than Dave's, but I find it easier to read:

for (let i = 0; i < myRandomList.length; i ++) {
  console.log(`Item ${i} in the array is ${myRandomList[i]}`)
}

1 Answer

Jordan Hoover
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jordan Hoover
Python Web Development Techdegree Graduate 59,268 Points

No reason not to, that's a point of personal preference. In the wild you'll find a lot of times when you can do something multiple ways, especially with Javascript. Usually, try to follow the code guidelines for the project or what fits the situation best.

Mike Hatch
Mike Hatch
14,940 Points

Thank you. Right, I know you can do something multiple ways. Dave even says that in the video. Just wanted confirmation because it seemed like a more efficient way to use a template literal, but you never know..

Mike Hatch
Mike Hatch
14,940 Points

You're a good man, Charlie Brown.