While Loop Help

Hello, can anyone please help me with the while loop code

Here is the link to the lesson: https://www.codecademy.com/courses/introduction-to-javascript/lessons/loops/exercises/while

And here is my code: const cards = [‘diamond’, ‘spade’, ‘heart’, ‘club’];

// Write your code below

let currentCard;
while (currentCard = card[Math.floor(Math.random() * 4)])

If possible please help me


If you post code, please make sure it is formatted: How do I format code in my posts?

Then, to get closer to a working code snippet, let’s start with the syntax for a while loop:

while( a condition is fulfilled ) {
  do what is inside the curly braces

Can you take that snippet and write in your own words what you want your code to do?


i just do not understand

Code: `const cards = [‘diamond’, ‘spade’, ‘heart’, ‘club’];

// Write your code below

let currentCard;
while (‘spade’ !== currentCard) {
= card[Math.floor(Math.random() * 4)];

sorry i did not format my code, i do not understand how to

Have a look at: [How to] Format code in posts

Basically, you can click on the </> button in the forum post editor, and then copy paste your code in between the pair of three backticks,

copy paste code here

1 Like

ok, thanks a lot for your help