skip to Main Content

How to shuffle cards in javascript?

let cards = ["A","2","3","4","5","7","8","9","10","J","Q","K"]; shuffle(cards); console.log(cards); function shuffle(array){ let currentindex = array.length; while (currentindex !=0) { let randomcards = Math.floor(Math.random()* array.length) currentindex -=1; let temp = array[currentindex]; array[currentindex] = array[randomcards]; array[randomcards] = temp} return array } My teacher taught me…

VIEW QUESTION
Back To Top
Search