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 Build a Two-Dimensional Array

my version of the createDec function, its better or worse?

const 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:
  //i loop through the suites array
  for(let k = 0; k < suites.length; k++) {
    //then i loop through the ranks array
    for(let l = 0; l < ranks.length; l++) {
      //then i declare an array called card and insert to the array the specified rank and suite of the iteration, the card contain for example a "card" like >> ['♥︎', 2]
      let card = [ranks[l],suites[k]];
      //finally after i inserted the rank and the suite i add the "card" to the deck array.
      deck.push(card);    
   }
 }
  shuffle(deck);
  return deck;
}

instead of using the push() method to build the "card" array, in my solution I just insterted each of the rank and suite of the specified iteration and then added them to the deck array as an array already.

what do u think about my solution?, the teacher's way is also very good but i didnt thought about it :}

1 Answer

Hello <noob/>. I found this way easier to understand then the teachers method. So while it might not be superior I found it easier to understand where I went wrong in my code. So thanks!