JavaScript While loop lesson mistake?


#1

https://www.codecademy.com/courses/learn-javascript-loops/lessons/loops/exercises/while?action=lesson_resume&course_redirect=introduction-to-javascript

According to the instructions, the while loop will never execute, since this is what you get



let cards = ['Diamond', 'Spade', 'Heart', 'Club'];

let currentCard = 'Spade';

while (currentCard !== 'Spade') {
  console.log(currentCard);
  currentCard = cards[Math.floor(Math.random() *4)];
}

console.log('You found a spade!'); 


The currentCard is said to be ‘Spade’ instead of something else like ‘Hearts’, as shown in the hint.
I am certain, I have followed the instructions right, even though I noticed quick enough they would not work, however I may be wrong, can you please let me know If I am wrong somehow?


#2

which step of the instructions are you stuck at? there are 4 steps

assuming you refer to the hint (which is only present at step 4), i assume you are at step 4

the instructions of step 4 say:

Change the currentCard that you set to ‘Spade’ in the first step to ‘Heart’ so that the program will run.

you need to change already existing code, so that the loop actually runs


#3

It seems I am an idiot, I must have misread it.
I took it as assigning it to ‘Heart’ in a new variable instead of changing the original one.

Thank you.


#4

i guess you misread it, thankfully then there is a forum where you can get help :slight_smile:


#6

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