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

Maxim Melnic
Maxim Melnic
4,178 Points

var card = [ranks[i], suites[l]];

Hi, i can use this method?

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 (var l = 0; l < suites.length; l += 1) { for (var i = 0; i < ranks.length; i += 1) { var card = [ranks[i], suites[l]]; deck.push(card); ...

in video with solution

let card = []; card.push(ranks[i], suites[l]);

or this line var card = [ranks[i], suites[l]]; add array in array and in array? It's work but can there be a mistake in this?

1 Answer

Using 'i' and 'I' as loop variables for nested for loops can be risky. As you mention, it would be easy to make a mistake. I suppose it is not much different from the use of 'i' and 'j' that is common. The biggest problem is that 'I' and '1' look very similar in some fonts. Try to make your code easy to read.