Reputation: 1
First of all I want to tell you that I am currently learning javascript, and I have run into a problem. I have tried most of the methods I have learned so far and could not do it. If someone could tell me how it works I would appreciate it.
This is the while loop I can't pass it to a for loop
const cards = ['diamond', 'spade', 'heart', 'club'];
let currentCard;
while (currentCard != 'spade') {
currentCard = cards[Math.floor (Math.random () * 4)];
console.log(currentCard);
}
I really wish I could understand how to take this while loop to a for loop
Upvotes: 0
Views: 54
Reputation: 1631
Well, this is kinda cheating, buy hey, this isn't wrong :-)
const cards = ['diamond', 'spade', 'heart', 'club'];
let currentCard;
for (;currentCard!='spade';) {
currentCard = cards [Math.floor (Math.random () * 4)];
console.log (currentCard);
}
Upvotes: 3