Freecodecamp: Checkpoint: Counting CardsCheckpoint: Counting Cards

Created on 5 Jan 2016  路  4Comments  路  Source: freeCodeCamp/freeCodeCamp

help please to solve the issue>>>

var count = 0;

function cc(card) {
// Only change code below this line
if(card==2 ||card==3 || card==4 || card==5|| card==6)
count++;
else if(card==7 || card==8 || card==9)
count+=0;
else if(card == 10 || card =='j'||card=='Q'||card=='K'||card=='A')
count-=1;

if(count<0){return count+"Hold";}
else if (count>0){ 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');

Most helpful comment

@MariamShqair

Please ask for guidance at Help Chat, you will get instant help, github issues are for bugs.

Your code is correct, except just make the below changes to get this working.

In the check for the 10, 'J', 'Q', 'K','A' you have :
else if(card == 10 || card =='j'||card=='Q'||card=='K'||card=='A')
change that to :
else if (card == 10 || card == 'J' || card == 'Q' || card == 'K' || card == 'A')

The J needs to be in Upper Case.

Next in a condition check where you are creating the return string
if(count<0){return count+"Hold";}
change the condition check to :
if (count <=0)

Need an = there.

Finally add some space in the string like below :
return count+" Hold"; instead of return count+"Hold";

Goodluck!

All 4 comments

@MariamShqair

Please ask for guidance at Help Chat, you will get instant help, github issues are for bugs.

Your code is correct, except just make the below changes to get this working.

In the check for the 10, 'J', 'Q', 'K','A' you have :
else if(card == 10 || card =='j'||card=='Q'||card=='K'||card=='A')
change that to :
else if (card == 10 || card == 'J' || card == 'Q' || card == 'K' || card == 'A')

The J needs to be in Upper Case.

Next in a condition check where you are creating the return string
if(count<0){return count+"Hold";}
change the condition check to :
if (count <=0)

Need an = there.

Finally add some space in the string like below :
return count+" Hold"; instead of return count+"Hold";

Goodluck!

@raisedadead

Thanks..
^_^

_removed answer_

I think this code is make more sense. hope it will help you.

nice and clean ;-)

function cc(card) {
// Only change code below this line
switch(card){
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
case 7:
case 8:
case 9:
count+=0;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count-=1;
break;
}
return count <= 0 ? '${count} Hold' : '${count} Bet';

// Only change code above this line
}

Was this page helpful?
0 / 5 - 0 ratings