Help me! JavaScript Counting Cards

Tell us what’s happening:

Your code so far


var count = 0;

function cc(card) {

  // Only change code below this line
  var co;
   switch(card){
     case 2:
     case 3:
     case 4:
     case 5:
     case 6:
       count++;
       break;
    case 7:
    case 8:
    case 9:
      count==0;
      break; 
    case 10:
     case 'J':
     case 'Q':
     case 'K':
     case 'A':
        count--;
        break;    
   }
    if(count>0){
    co= "Bet";
  }
  else{
    co= "Hold";
  }

  
  return count+co;
  
}

You need a space between count and co

i did it, but still it’s not working

I haven’t tackled this challenge, so if you could explain the objective of the code or the expected outcome of the code then I could help. Nevertheless at case 9: count == 0; I believe should be count = 0 and not count == 0. count == 0 has no effect on the count variable - unless you want a boolean outcome.

could you post the code of what you tried to add the space?

The challenge say to not reset the count variable to 0, in that case it needs to stay unchanged

the code posted is not resetting count, it’s using a comparison operator not an assignment.
If the space is correctly added it passes, most likey @fccb988c681-323f-44b is not adding the space correctly

can you please share a link to the challenge?

It’s this one

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/counting-cards

Great so i @Dereje1 has pointed out that there should be a space in-between count and co. I guess that’s a requirement of the challenge. You can achieve that with return count+" "+co rather than return count + co
Try it and let’s see

If you want to help someone, are you sure that giving them the answer to copy&paste is the best thing for them to learn?

Well, it depends on the perspective you look at it from. I would say yes and no. As an anagram, It would be easier to show someone a banana or an image of a banana than trying to describe a banana with words and more especially when typing.
I think if there are parts of a copy and past code you are not familiar with you could seek further clarification.
What do you think?

1 Like

it is working, thank you

yep,i wasn’t add space correctly, thank you for helping me.

THE RIGHT CODE IS HERE!

<redacted>

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

If you want to compare your solution to others, use the Get a hint button on the challenge and there are alternative solutions you can compare yours to. Also, you can probably search older posts using the forum search feature or google the challenge name and find more there.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Thank you for understanding.