6.While loops


#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(currentCard);

//////////////////////////////////////////
Question:
Outside the while loop, on the last line of the program, use console.log to log that the program found a spade.

Run the code a few times to see the output changing. You can see the while loop guessing a card, then seeing if it is a Spade, over and over, until it finds one.

////////////////////////////////////////////////////////////////////

Because of my poor programming skill, I have no idea what should I do about this....

Does anyone tell me?


#2

I think you may be looking too deeply into this question.
It's simply asking you to log a string that says the program has found a, then currentCard.

Try something like this.

console.log('The program found a ' + currentCard);

Let me know if that worked.


#3

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