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

Gal Parselany
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Gal Parselany
Full Stack JavaScript Techdegree Graduate 26,281 Points

my solution:

function shuffle(arr) {
    let j, x, i;
    for (i = arr.length - 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() {
const suites = ['♠︎','♣︎','♥︎','♦︎'];
const ranks = ['Ace','King','Queen','Jack','10','9','8','7','6','5','4', '3','2']
let deck = [];
for (i=0; i < suites.length; i++) {
    console.log(suites[i])
    for (j=0; j < ranks.length; j++) {
        console.log(ranks[j]);
        let card = [`${ranks[j]} ${suites[i]}`]
        console.log(card);
        deck.push(...card);
    }
}
return deck;
}
let myDeck = createDeck();
shuffle(myDeck);
console.log(shuffle(myDeck));

for (i = 0; i < myDeck.length; i++) {
    console.log(`${myDeck[i]}`);
}

Do you think something is wrong here? Please tell me; thanks in advance.

Rich Donnellan
Rich Donnellan
Treehouse Moderator 27,696 Points

The question was updated with code formatting. Check out the Markdown Cheatsheet below the Add an Answer submission for syntax examples, or choose Edit Question from the three dots next to Add Comment to see how I improved the readability.