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

<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.>
6) While Loops
<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
Every time I click run, I get the following message:

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

:disappointed_relieved:
PLEASE HELP!!!

Did you try refreshing the page and resubmitting? Or trying to submit on a different browser?

Yes I refreshed, resubmitted, and submitted on a different browser. It still gives me the same error message.:disappointed:

I’m pretty sure it’s a bug on codecademy’s end. ::crying_cat_face:

I tried reporting the bug and they sent me an email saying someone will be with me shortly, but that was about a month ago. In addition, I can’t progress to the next exercise. I’ll try again, but thanks a lot for your help. :pray:

1 Like

I am sure you have tried this but its worth a shot if you want to go to another computer and try submitting it. I have heard it works sometimes but yeah this seems to be somewhat of a consistent problem in some lessons if not caused by infinite loops and such.

Is it checkpoint 2 that you are trying to get past?

Yes I did try this, on multiple computers even, but thanks for the tip.:relaxed:

1 Like

I don’t really know what you mean by this, but I’m on the “Learn JavaScript” course (preview version) and I am on section 4, “Arrays and Loops”. I’m on the “Loops” part of this section, exercise 6, “while loops”, to be exact. Since I am getting an error message saying something is wrong (even though it isn’t) I am not allowed to progress to the next exercise or section.:confounded:

This is checkpoint 2 for the link that you originally posted:

Is this the one you are stuck at, is yours green or red?

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

That is the code that I keep trying to run, but every time I get the same error message:

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

I know I did that, but I tried so many times that I was asked if I wanted the correct code. I agreed and got the same code that I typed in. Also, I got the same error message each time I ran the code.

1 Like

It’s red, I don’t know why.:thinking::sob:

It’s red because your code doesn’t do what that checkpoint is asking for.

Delete everything AFTER this line:

var currentCard = 'Heart';
1 Like

Thanks so much for your help. :grinning::blush::stuck_out_tongue_closed_eyes:

2 Likes

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