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 JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays What is an Array?

Ability to store values from functions inside arrays, and then pulling them out one at a time later?

Dave McFarland This question is mostly for you, but anyone else that can answer I would be grateful. It has nothing to do with this video, other than I came up with the idea of using arrays, and it just so happens this video is on arrays.

I am writing some other side JavaScript codes to just have extra practice going along. One of the scripts I am writing was having to use the random number generator through a function() or a for() loop, and having it repeat a specified amount of times.

The idea is that each time the the code cycles through, the resulting random number will be added to a specific variable. So, having read on JavaScript over the years, the idea that I had was to have the function() or the for() loop put ALL of the random numbers generated into an array, that I can later access each part of the array and assign it to a specified variable.

Just real quick, is this something that is possible (if so, I'll figure the proper coding out)? Will we be doing something along these lines in some upcoming videos or later courses of the Full Stack JavaScript track?

As always, thanks.

Umesh Ravji
Umesh Ravji
42,386 Points

I don't recall doing anything like that in the FS JS track, but what your asking for seems fairly straight forward.

1 Answer

Gabriel Kartak
Gabriel Kartak
5,399 Points

Hi Michael. Yes creating a list of random numbers and assigning them to an array is possible, but I'm not sure if you will do something similar in the full stack javascript course.