Advertisement
karlakmkj

while loop

Dec 10th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const cards = ['diamond', 'spade', 'heart', 'club'];
  2.  
  3. let currentCard;
  4.  
  5. while (currentCard !='spade'){
  6.   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.
  7.   console.log(currentCard); //hence the currentCard array will have different elements each time you run based on the cards array
  8. }
  9.  
  10.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement