Shuffle decks in javascript
<script>
function createCardsforShuffle(){
const suits = ["Spades", "Diamonds", "Club", "Heart"];
const deck = [
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"Jack",
"Queen",
"King",
];
let deckvalue = [];
for(var countSuits = 0; countSuits < 4;countSuits++){
// console.log(suits[countSuits]);
for(var countdeck = 0; countdeck < 13;countdeck++){
//console.log(deck[countdeck]);
deckvalue.push(deck[countdeck] + suits[countSuits]);
}
}
return deckvalue;
}
function shuffleCards(decks){
for(var i=0;i<52;i++){
var temp = decks[i];
var randomCards = Math.floor(Math.random() * 52);
decks[i] = decks[randomCards];
decks[randomCards] = temp;
}
}
var testCardsForshuffle = createCardsforShuffle();
shuffleCards(testCardsForshuffle);
console.log(testCardsForshuffle);
</script>
Thanks you for commenting your questions. I will see question and respond you.