Exercise 6



Did you set the variable currentCard equal to 'Heart'?

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

var currentCard = 'Heart';

while (currentCard !== 'Spade') {

  var randomNumber = Math.floor(Math.random() * 4);
  currentCard = cards[randomNumber];
console.log('Found a Spade!');

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']
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.