'while' Loop


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

var currentCard = 'Heart';

while (currentCard !== 'Spade') {

  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!!


while (currentCard !== 'Spade')

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


Ohhhh, okay, thanks!!


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