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 Object-Oriented JavaScript: Challenge Rendering the Game Getter Methods Solution

Ryan Belshaw-Weir
Ryan Belshaw-Weir
5,721 Points

Is return this.unusedTokens.shift() the same as return this.unusedTokens[0]?

I was wondering is there any difference between the Is return this.unusedTokens.shift() and this.unusedTokens[0]?

2 Answers

Steven Parker
Steven Parker
229,644 Points

Both of those expressions will return the first token, but when you use "shift" it removes it from the array.

Ryan Belshaw-Weir
Ryan Belshaw-Weir
5,721 Points

That's what I thought but if I log game.activePlayer.unusedTokens to the console before and after the shift expression it is the same. Why is that?

Steven Parker
Steven Parker
229,644 Points

Perhaps "this" is something other than "game.activePlayer", and you're looking at the wrong list.

If you still have trouble, make a snapshot of your workspace and post the link to it here.