My lunch time with Javascript tutorial on codecadamy.com.
I have this simple loop:
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!');
This goes fine, but if I remove randomNumber from loop and place with other global variables, codecademy console doesn't print the result...
Since that global variables should be available to that loop, I assume that something is wrong with codecademy console?
Do you agree that this supposed to work?
var cards = ['Diamond', 'Spade', 'Heart', 'Club'];
var currentCard = 'Heart';
var randomNumber = Math.floor(Math.random() * 4);
while (currentCard !== 'Spade') {
console.log(currentCard);
currentCard = cards[randomNumber];
}
console.log('Found a Spade!');