Exercise 6


#1

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

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


can't get it to work... thx


#2

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?


#3

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


#4

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?


#5

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