7. The while loop - Step 2


#1

My answer:

const cards = [‘diamond’, ‘spade’, ‘heart’, ‘club’];

// Write your code below
let currentCard;
while (currentCard !== ‘spade’) {
currentCard = cards[Math.floor(Math.random() * cards.length)];
console.log(currentCard);
}


My question:

For step 2 it ask you to use:
currentCard = cards[Math.floor(Math.random() * 4)];

Is there any advantage or disadvantage to use:
currentCard = cards[Math.floor(Math.random() * cards.length)];



#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.