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 trialken perkerwicz
6,167 Pointscan someone please show me where the suit is stored in the second position of the nested array? (8:23)
In the video Dave mentions how 'the suit is in the second position of the nested array'. I am unsure of where to see this in the code. Can someone please help me locate this? Thanks!
2 Answers
KRIS NIKOLAISEN
54,971 PointsWatch the video @ 4:14 for this line:
card.push(ranks[j], suites[i]);
You can also see the suites in the second position in the video's workspace in example_2d_array.js
Mister Moody
48,333 PointsWorking Solution:
function shuffle(arr) {
var j, x, i;
for (i = arr.legnth - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1));
x = arr[i];
arr[i] = arr[j];
arr[j] = x;
}
return arr;
}
function createDeck() {
var suites = ['spades', 'clubs', 'hearts', 'diamonds'];
var ranks = ['Ace', 'King', 'Queen', 'Jack', '10', '9', '8', '7', '6', '5', '4', '3', '2'];
var deck = [];
for (let i=0; i<suites.length; i++) {
for (let j=0; j<ranks.length; j++) {
let card = [];
card.push(ranks[j], suites[i]);
deck.push(card);
}
}
return shuffle(deck);
}
for (let i=0; i<myDeck.length; i++) {
console.log(myDeck[i]);
}