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

Letters not printing.

Making a little program that's still under construction. My problem is that the unshuffled/original sequence of letters wont print and only the shuffled letters will. Specifically lines 51 and 56. Lines 41 and 42 show that the variable declarations used for 51 and 56 are different. However 51 is only printing out as 56. Any help would be appreciated.

Here is a link to the code: https://w.trhou.se/df3oawmdk6

1 Answer

Steven Parker
Steven Parker
243,656 Points

You're shuffling the original array.

You're using a different variable name, but it's assigned as a reference to the original, so after calling shuffle, the original array has changed.

If you want to retain the original array in the order it was randomly picked, you can copy the array using slice:

  let switchLetters = letters.slice(0);

I'd be interested in seeing what this does when you finish. Perhaps you'd post another snapshot then.

It worked! I was treating my arrays like primitive types which they are not. Will do some further reading on this. So THANK YOU for helping me understand/realize that!