Counting cards and its mysteries

Tell us what’s happening:
Hi, everyone Here’s the problem.My code only works for the 1st sequence of cards 2,3,4,5,6 and …that’s all .Can someone point me towards the course I obviously didn’t understood .I can’t find the “why” it works only for one sequence and it’s driving me crazy .

  **Your code so far**

var count = 0;

function cc(card) {
// Only change code below this line
if (card = 2 || 3 || 4 || 5 || 6) {
} else if (card = 10 || 'J' || 'Q' || 'K' || 'A') {
if (count >= 1) {
  return count + " Bet";
} else if (count < 1) {
  return count + " Hold";

// Only change code above this line

cc(2); cc(3); cc(7); cc('K'); cc('A');
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0.

Challenge: Counting Cards

Link to the challenge:

You have two issues here. First ,you need to make sure you understand what card = 2 does. Hint, it is not a comparison. Second, if you want to compare the same variable to multiple values, you must make the comparisons individually. You can not simply put the variable on the left followed by a bunch of logical operators and values on the right of it. You literally must compare each value to the variable multiple times.

I suggest looking at the example in the previous lessons, because there has been nothing presented showing comparisons like you are attempting to do here.

fixed it by changing the = to === and as you said I compared each value individually and it works . Thank you very much . But I thought since we learned about && and || it could be used since different cards have the same output .I guessed wrong

You can use || and && in this challenge, but you have to use it correctly. Each side of the || or && must have a complete logical condition rather than just a single letter or number.

thank you for answering . I understand why using || was wrong in my case, which brings me another question : Why did it worked on the 1st sequence ?
Ok I’m stupid , I think I know why

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