Counting cards(fcc)

This code is not working,The logic is a bit confusing
/
var count = 0;

function cc(card) {
// Only change code below this line
switch(card){
case 2:
count++;
break;
case 3:
count++;
break;
case 7:
count++;
break;
case ‘K’:
count++;
break;
case ‘A’:
count++;
break;
}
if(cc == 2){
count++;
}
else if(count == 3){
count++;
}
else if(count == 7){
count++;
}

else{
count–;
}

return count;
// Only change code above this line
}

// Note: Only the last will display
console.log(cc(2));
console.log(cc(3));
console.log(cc(7));
console.log(cc(‘K’));
console.log(cc(‘A’));
/

if(cc == 2){
count++;
}

I think it should be count not cc in the above if statement condition I have pointed out

Yeah that was a mistake ,but still I am not getting the final output

I see few syntax errors. What should be your final output?

I am getting all 0’s.

I have tried a different code

var count = 0;

function cc(card) {
// Only change code below this line
switch(card){
case 2:
case 3:
count++;
break;
case 7:
count;
break;
case ‘K’:
count–;
break;
case ‘A’:
count–;
break;
}
if(count > 0){
return ‘Bet’;
}
return count;
// Only change code above this line
}

// Note: Only the last will display
console.log(cc(2));
console.log(cc(3));
console.log(cc(7));
console.log(cc(‘K’));
console.log(cc(‘A’));

Add other cases as well. You missed out some card values in your switch statement.

Also correct your return statement. It should be:
if (count > 0)
return count + ’ Bet’;
else
return count + ’ Hold’;

We have the the function calls as cc(2),cc(3),cc(7),cc(‘K’),cc(‘A’),so what I dont understand is why do we have include all the other switch statements.

Because you need to make your code reusable, not specific for this situation.
And the tests check various other cases.

everything works but the output is
1 Bet

2 Bet

0 Hold

-1 Hold

-2 Hold
which should only return -1,0,1 but not 2 or -2

var count = 0;
var hold = ‘Hold’;
function cc(card) {
// Only change code below this line
if(card == 2){
count++;

}
else if(card === 3){
count++;

}
else if(card === 4){
count++;
}
else if(card === 5){
count++;
}
else if(card === 6 ){
count++;
}
// lower counts

//neutral counts
if(card === 7){
count = 0;
}
else if(card === 8){
count = 0;
}
else if(card === 9){
count = 0;
}

if(card === 10){
count–;
}
else if(card === ‘J’){
count–;
}
else if(card === ‘Q’){
count–;
}
else if(card === ‘K’){
count–;
}
else if(card === ‘A’){
count–;
}
if(count > 0){
return count + ’ ’ +‘Bet’;
}
return count + ’ ’ + hold;
// Only change code above this line
}

// Note: Only the last will display
console.log(cc(2));
console.log(cc(2));
console.log(cc(7));
console.log(cc(‘K’));
console.log(cc(‘A’));

which should only return -1,0,1 but not 2 or -2

Why do you think so?

You have a global variable, each time the function is called that global variable has its value altered

Also, the correct `count` values in that card sequence should be 1 2 2 1 0

Don’t do this, you just have to not change the global variable, not reset it to 0. The challenge is specific on this.
Also `cc(2); cc(2); cc(2); cc(2); cc(7);` the expected result is `"4 Bet"` instead with your code the result is `"0 Hold"`

Your older code was working fine. You just have to add cases for the missing card values in your switch statement and in your if condition you have to change your return statement. You have to add the missing card values because your program should be able to compute results for those values as well. The test calls of the function are just for testing purposes.