6/7 reassign array value


I’m having a tough time understanding when asked to “…Then use the randomNumber to reassign currentCard to a new card from the cards array…” in the following code… why a number doesn’t print out on the console? Maybe a better question would be… how does reassigning the value in the array for variable cards work out in a string being printed? Thank you.

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

while (currentCard !== ‘Spade’) {
var randomNumber = Math.floor(Math.random() * 4);

currentCard = cards[randomNumber]; // I don’t understand why this works out in a string being printed instead of a random number??

console.log('The program found a: ’ + currentCard + ‘!!!’);


The random number is the index of the string in the array.


Oh I see now :)!! Thank you so much for clarifying. Cheers!!


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