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

I found another way to complete this project but I am not sure if it is the best way.

In this challenge I ended up programming the challenge in this way. I am not sure if this way is best practice but it yields the same results. Can someone explain why the solution in the video would be better than what I did. The only reasons I can see would be that it would be somewhat cleaner as you can define the "array" variable in the function.

let array = []; let message =[];

function createRandomList(){ for (let i=0; i< 10; i++){ array.push(random100()); } } const myRandomList = createRandomList()

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

Thanks for any responses!