Exercise 6

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

https://www.codecademy.com/courses/learn-javascript/lessons/loops/exercises/while?action=lesson_resume&link_content_target=interstitial_lesson
<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

Did you set the variable currentCard equal to ‘Heart’?

```

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!’);

<do not remove the three backticks above>
can't get it to work... thx

After running that code, what will that variable refer to? How does that relate to your error message? And the instructions of your current checkpoint?

here are the instructions:
Let’s write a program that flips cards until we get a ‘Spade.’ Start by creating a variable named cards and set it equal to this array:

[‘Diamond’, ‘Spade’, ‘Heart’, ‘Club’]
2.
Right under the array create a variable named currentCard and set it equal to ‘Heart’.

This variable will hold the name of the card we just flipped. We are using ‘Heart’ as the first card.

I am on step 2, I tried multiple times and I can’t find my error

I really did not need to know the instructions. You did! Have you considered the rest of what I said? In particular, what will your variable refer to by the time your code finishes? What do the instructions say it should refer to? Do those two answers match?

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