'while' Loop


#1


var cards = ['Diamond', 'Spade', 'Heart', 'Club'];

var currentCard = 'Heart';

while (currentCard !== 'Spade') {
  console.log(currentCard);

  var randomNumber = Math.floor(Math.random() * 4);

  currentCard = cards[randomNumber];
}

console.log('Found a Spade!');

I used 'Get Code' after many futile attempts to get the code running to get a 'Spade'. Even after using the code provided, it seems that every time I run it, I never get a Spade. It is possible that the code is faulty, and that it is impossible to get a Spade? I checked all the other discussions and it seems that it was never answered. Thanks a lot!!


#2

while (currentCard !== 'Spade')

consider this line of code.
when currentCard will be Spade will your code run?


#3

Ohhhh, okay, thanks!!


#4

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