Code analysis of Basic JavaScript: Counting Cards

Tell us what’s happening:

I just wrote this code that does not work properly and I can’t figure out why.
It should eveluate the numeral values, add 1 or nothing and subtract 1 in all other cases.
There must be a logical pit but that I can not see.
By the way, it’s not a great code even id it worked…

Your code so far

var count = 0;

function cc(card) {
  // Only change code below this line

  if (card >= 2 & card <= 6){
    count ++;
  else if (card >= 7 & card <= 9) {
    //do nothing
    count --;

  if (count > 0){
    return count + " Bet";
    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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.

Challenge: Counting Cards

Link to the challenge:

can you see a patter of the tests that fail?

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 3, 2, A, 10, K should return -1 Hold

So, there seems to be something wrong with those that returns an Hold
Do you see any difference in your code between the line that returns Bet and the one that returns Hold?

1 Like

There is also a couple of wrong types of logical operator. Instead of using & which on JavaScript is a BitWise operator, which uses numerals. Use && which is a comparison operator. You can learn more about javascript operator here:

Thank you everyone,

found the typos and it’s now working (still not great code in my view )