While loop never returns a 'Spade' altho that's what program is supposed to do


#1

My code below is correct, not getting errors, and I followed directions - it’s supposed to loop ‘cards’ until it logs a ‘Spade’ but with the code:

'while(currentCard !== ‘Spade’)

the loop never returns a ‘Spade’ - it returns everything else. I substituted ‘Diamond’ and then got plenty of spades but never a ‘Diamond’, so if I’m asking it to return something if the currentCard is not a Spade, how will it loop until it returns a Spade, which I believe is what running the program multiple times is supposed to illustrate?

I either don’t understand the exercise, or the code is wrong, but I’ve double and triple checked it.
Any advice?
Thanks!

THE CODE:

let cards = [‘Diamond’, ‘Spade’, ‘Heart’, ‘Club’];

let currentCard = ‘Heart’;

while (currentCard !== ‘Spade’){
console.log(currentCard);
currentCard = cards[Math.floor(Math.random() * 4)];
}
console.log(‘found a spade’);


#2

Please remember to include a link to the exercise when posting a lesson related question.


#3

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