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!
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
Gal Parselany
Front End Web Development Techdegree Graduate 20,051 Pointsmy 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
Treehouse Moderator 25,869 PointsRich Donnellan
Treehouse Moderator 25,869 PointsThe 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.