# Counting Cards!help me!

Counting Cards!help me!
0

#1

Tell us what’s happening:

``````
var count = 0;

function cc(card) {
// Only change code below this line
if (card <=6 && card>=2)
{
count =count +1;

}
else if (card<=9 && card>=7 ){
count =count+0;

}
else{
count =count -1;
}

// Only change code above this line
}

// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
if(count>0){
return count,"Bet";
}
else if(count<=0){
return count,"Hold";
}

``````

User Agent is: `Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36`.

#2

This is a very good first start!

Firstly, you seem to have accidentally put some of the code outside of the function – when it has `return` statements and the like. That bit of code is below:

``````if(count>0){
return count,"Bet";
}
else if(count<=0){
return count,"Hold";
}
``````

You need to move it to the correct position, or else your code will throw an error and won’t run. That’s because the `return` statement errors when it’s not inside a function, because it doesn’t know what to do exactly.

In addition, in JavaScript, the comma (`,`) operator will evaluate each of its statements and then return the last in the sequence (technically, it only takes two arguments and binds left-to-right, but that isn’t important).

``````function example() {
return 1, 2, 3, 4 // returns 4
}
``````

Likewise, the statement

``````return count,"Hold";
``````

is identical to

``````return "Hold";
``````

And that definitely won’t pass any of the tests. Instead, to join two strings together, we can use the concatenation operator (`+`). If we pass it a number and a string, it will coerce the number into a string and then join them together. So, `1 + "Bet"` will be `1Bet`.

But what you want, I suspect, is `1 Bet` (with a space between the two). You can include spaces in JavaScript strings, so you just need to change `"Bet"` to have a space at the start. Note that `( "Bet")` (i.e., placing the spaces before the `"`, won’t work, because it’s not part of the string, but part of the code).

Once those issues are fixed, it might be a little easier to solve your problem. Good luck!

EDIT: I made the changes I just described above, and managed to get it to work. To summarise, those changes were:

1. Move the stray bit of code back into the function
2. Change the `,` operator to instead concatenation (`+`) operators
3. Make sure there is a space between the number and the “Bet” or “Hold” text