Basic JavaScript: Counting Cards Help

Hello I want to know why my code won’t work. I feel like the if and else statement are what should work for the last part

var count = 0;

function cc(card) {
  // Only change code below this line
    case 2:
    case 3: 
    case 4: 
    case 5: 
    case 6:
    count += 1;
    case 7:
    case 8:
    case 9:
    count += 0;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
    count -= 1;
   if(count <= 0){
      return count + "Hold";
    } else {
      return count + "Bet";
  // 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');```

You are very close. Currently, your code will return values like “5Bet” or “-2Hold”.

Your return value’s format is wrong. Try to log it in console and compare with the requirement.

Is my return statement wrong? I saw some other examples but I feel like this one could also be used

EDIT: Nevermind I figured out that there was a space needed between the strings haha

Your return statements are wrong. Look carefully at the string you should be returning vs. what you are returning. I gave you a big hint. I will give you another.

Instead of “5Bet”, you should be returning “5 Bet”.

Hi, I am a JS newbie. My understanding of the scripting language is advancing. So my question here is - since the count variable was declared as global scope, how is it that when the function cc was initiated, that the count variable can be used with the local scope of that function?

along with:

Any variable in the global scope can be used by any function.

1 Like

Okay, so a local variable won’t be able to use a global scope variable.

I am not sure what you mean by a local variable won’t be able to use a global scope variable. It is not a matter of a local variable using a global scoped variable. It is that variables scoped inside a function (locally scoped) are not accessible from the global scope or anywhere outside that function. A globally scoped variable is accessible from anywhere.

1 Like

I am having trouble the concept of console.log()
Could you please explain how you would log this example into the console?
Thank you!

I don’t know what you actually mean, you can just type console.log(whatever) and it will be logged in the console. If you still have question, you can paste your code here and let us see what is going wrong.