# Counting Cards[ solution for this?]

Counting Cards[ solution for this?]
0

#1

Tell us what’s happening:

``````
var count = 0;

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

if(card>=2 || card<=6){
return "5 Bet";
}else if(card==7 || card==8 || card==9){
return "0 Hold";
}else if(card==10 || card=="J" || card=="Q" || card=="K" || card=="A"){
return "-5 Hold";
}
else if(card==7 || card==7 || card=="Q" || card==8 || card=="A"){
return "-1 Hold";
}
return "Change Me";
// Only change code above this line
}

// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');cc(8);cc(9);
``````

User Agent is: `Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0`.

#2

Hi !
I believe you did not understand the concept of the question.
You will receive a sequence of cards. Based on those cards, you will count: add 1 if cards between 2 & 6; subtract 1 if cards between 10 & ‘A’. (the other cards don’t change the counter). Once you have gone through the sequence of cards, then you will produce the result: if count > 0, your current count plus ‘Bet’, if count <= 0, your current count plus ‘Hold’.
Does this help?

#3

EDay69 is right. You’ve not quite understood what the cc() function needs to do:

First update the global `count` variable based on the current card passed in as an argument. Right now, your function doesn’t touch `count` at all.

I would recommend focusing on this task first. Make sure that calling cc() updates `count` as required. Your if-else structure is attempting to do this, but it has some problems. First of all, the code in that chain of if-else statement should NOT return anything. It should merely update the value of `count`.

In addition, there are some problems with the boolean expressions that are controlling the structure. For example `card >= 2 || card <= 6` will return true for any number at all because every number is either greater than 2 or less than 6.

Once you are sure that the first part of your function is updating the value of ‘count’ correctly, then add additional code to check the new value of `count` and return a bet/hold recommendation.

#4

i ddont know why it is not working, please check my code

``````ar count = 0;

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

return "Change Me";
// Only change code above this line
}

// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
``````

#5

Please read my comment above. There are many reasons why it is not working.

If you want to work through them issue by issue, start with this:

``````if(card>=2 || card<=6) {
return "5 Bet"
}
``````

Right now this code is causing your function to return ‘5 Bet’ whenever the card is greater than or equal to 2 OR less than or equal to 6. That is wrong.

What it should be doing is adding 1 to the `count` variable whenever the card is greater than or equal to 2 AND less than or equal to 6.

Perhaps see if you can just fix that small issue first.