Counting Cards Tutorial 2020

Tell us what’s happening:

Hi, I am using the below code and don’t understand why it isn’t working. Any suggestions would be helpful. Thanks

Your code so far


var count = 0;

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

if(card > 1 && card < 7) {
count = count++;
} else if (card === 10 || card === String) {
count = count--;
}
count > 0 ? count + 'Bet' : 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');

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134.

Challenge: Counting Cards

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/counting-cards

  1. This is not doing what you think it is:
  1. There is no left-hand side of this operation:
  1. This is missing spaces:
  1. Your function doesn’t return anything.

Welcome to the forum!

Unfortunately you have at least 4 errors you need to fix.

  1. You are not explicitly returning a value from your function.

  2. When you actually do return a value based on count (like you are trying to do), there should be a space between the actual count value and the word “Hold” or “Bet”.

  3. count = count++ and count = count-- does not do what you think it is doing. Research the difference between putting the ++ before and after a variable.

  4. The second comparison in your else if card === String is not doing what you are hoping it is doing. You are comparing card (a string or number) to the String object. These will never be equal. Look into the typeof operator for how you could use it instead…