Counting Cards problem Help?

Not sure whats up with this i think it stops the sequence?

Cards Sequence 2, 3, 4, 5, 6 should return 5 Bet
Cards Sequence 7, 8, 9 should return 0 Hold
Cards Sequence 10, J, Q, K, A should return -5 Hold
Cards Sequence 3, 7, Q, 8, A should return -1 Hold
Cards Sequence 2, J, 9, 2, 7 should return 1 Bet
Cards Sequence 2, 2, 10 should return 1 Bet
Cards Sequence 3, 2, A, 10, K should return -1 Hold


var count = 0;


function cc(card) {
 
  // Only change code below this line
  if(1<card<7)
  {
     count++;
  }
   if(6<card<10)
  {
    count;
  }
  if(card === 10||card === "J"||card ==="Q"||card ==="K"||card ==="A")
  {
    count--;
  }
  
  if (count>0)
  {
    return count + " Bet"
  }
  else (count<=0)
  {
    return count + " Hold"
  }
    
    
    
  return "Change Me";
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc( );

can you share a link to the challenge you are at ?

You can not make two comparisons at the same time with a variable like you are trying to do in JavaScript. If you want to check if card is greater than 1 and card is less than 7, then you must write it as if (1 < card && card < 7). The && means AND.

Also, else statements do not have conditions as you have written. If you need another condition for certain code to execute you would write else if (the condition),

1 Like

Not sure what to do now,

Here is link to section of freecodecamp curriculum im on Click this


var count = 0;

function cc(card) {
  // Only change code below this line
  
  if(card>1 || card<7)
  {
    count++
  }
  else if (card === 7 || card === 8 ||card === 9)
  {
    count+=0
  }
  
  else(card === 10 ||card === 'J' || card === 'K' || card === 'Q' ||card === 'A')
  {
    count--
  }
  
  if(count>0)
  {
    return count + " Bet"
  }
  else{
    return count + " Hold"
  }
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

else statements to not have conditions. If you want to use conditions, then you need to write an else if statement.

1 Like