I am not sure what I am doing here, I am getting deck.length undefined in my shuffle funciton, can anyone tell me what I am doing wrong here? I tried many solutions to fix this problem and I can't understand why it is not working thanks.
function buildDeck() {
const suits = ['spades', 'hearts', 'diamonds', 'clubs'];
const ranks = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
const deck = []
for (i = 0; i < ranks.length; i++){
for (j = 0; j < suits.length; j++){
deck.push({rank: ranks[i], suit: suits[j], value: j + 0})
}
}
console.log(deck)
return deck
}
buildDeck()
function shuffle(deck){
shuffleDeck = deck
console.log(deck)
let currentIndex = deck.length
let temporaryValue = null
let randomIndex = null
while (currentIndex =! 0 ){
randomIndex = Math.floor(Math.random()*currentIndex)
currentIndex --
temporaryValue = shuffleDeck[currentIndex]
shuffleDeck[currentIndex] = shuffleDeck [randomIndex]
shuffleDeck[randomIndex] = temporaryValue
}
return shuffleDeck
}
shuffle(deck)