Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const cards = ['diamond', 'spade', 'heart', 'club'];
- let currentCard;
- while (currentCard !='spade'){
- currentCard = cards[Math.floor(Math.random() * 4)]; //Math.floor(Math.random() * 4) will give us a random number from 0 to 3. We’ll use this number to index the cards array, and assign the value of currentCard to a random element from that array.
- console.log(currentCard); //hence the currentCard array will have different elements each time you run based on the cards array
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement