Https://www.codecademy.com/courses/learn-javascript/lessons/loops/exercises/while


#1

"Did you write a console.log outside the for loop on the last line of the program?"

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('You found a ' + currentCard);


#2

It seems like you should write console.log('You found a Spade!'); instead of use currentCard variable.


#3

That seems silly. What if I wanted to change the program to be a different card....


#4

Well I agree, but in this exercise you need to write that you found a spade card. I tried modifying that in your code and it worked, so maybe it was the problem.


#5

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