Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Practice Basic Arrays in JavaScript!

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Use nested loops to build a multi-dimensional array.
Resources
- Fisher-Yates Shuffle Alogrithm
- Treehouse course: JavaScript Array Iteration Methods
Complete code
// 1. Add a for loop -- to loop through each element in the suites array
// 2. INSIDE that loop, add another loop that loops through elements in the ranks array.
// 3. Inside the second, nested loop, create a new array named card, which is composed of a rank and a suite. For example ['King', '♥︎'].
// 4. Push that card onto the deck array. Once both loops complete running, the deck array will hold 52 elements, and each of those elements are themselves an array.
// 5. Finally, pass the new deck to the shuffle() function, and return the results.
function createDeck() {
var suites = ['♠︎','♣︎','♥︎','♦︎'];
var ranks = ['Ace','King','Queen','Jack','10','9','8','7','6','5','4', '3','2'];
var deck = [];
// add your code below here:
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);
}
// 6. Call the createDeck() function and store the results in a new variable named myDeck
let myDeck = createDeck();
/* 7. Use a for loop to loop through the deck and list each card in the order the appear in the newly shuffled array. Use the log() method to print out a message like this, once for each card:
"7 of ♥.︎"
*/
for (let i = 0; i<myDeck.length; i++) {
console.log(myDeck[i][0]+ ' of ' + myDeck[i][1]);
}
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Gal Parselany
Full Stack JavaScript Techdegree Graduate 26,281 Points0 Answers
-
Frank Greek
Full Stack JavaScript Techdegree Student 981 Points2 Answers
-
Eric Peppler
3,675 Points0 Answers
-
Yuting Le
Full Stack JavaScript Techdegree Graduate 20,125 Points1 Answer
-
Eddy Yi
8,746 PointsCan I just do like this deck.push([suites[i], ranks[j]]); not making card variable?
Posted by Eddy YiEddy Yi
8,746 Points1 Answer
-
Jiten Mehta
Front End Web Development Techdegree Graduate 21,209 Points1 Answer
-
Samantha Atkinson
Front End Web Development Techdegree Graduate 40,307 PointsDid I console . log my Deck correctly?
1 Answer
-
Armin Kadic
16,242 Points1 Answer
-
MIHA W.LEE
PHP Development Techdegree Graduate 25,452 Points1 Answer
-
<noob />
17,063 Points1 Answer
-
ken perkerwicz
6,167 Points2 Answers
-
Marius Urbonas
7,921 Points1 Answer
-
Maxim Melnic
4,178 Points1 Answer
-
Ben S
5,638 Points1 Answer
-
Tani Huang
6,952 Points1 Answer
-
Tani Huang
6,952 Points1 Answer
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up