Counting card questions

Hey im up to counting cards but cant get past it.

Whats wrong with this code

``````
if (card <= 6){

count ++;

} else if (card >6 && card <10 ){

count = count + 0;

} else 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";

} else

return count + "Hold";
``````

Please can you send the exact code so iâ€™ll give you a specific answer,
but from this code card and count are undefined, I think you need to create a variable like:

``````var card=3;
var count=2;
``````

but iâ€™m still not sure because the complete code was not sent

please post your whole code and the challenge link

Iâ€™ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the â€śpreformatted textâ€ť tool in the editor (`</>`) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (â€™).

I think the problem is that you are missing white space in return.
With your current code, output will we â€ś4Betâ€ť or â€ś-3Holdâ€ť.
So instead of writing `return count + "Bet"`,
write `return count + " Bet"`
That should work.

1 Like

you have to declare the variable first and also initialize both of them with a suitable type

share your problem description, there are many unnecessary lines of card

dude! that worked thankyou so much!

complete code now this

``````var count = 0;

function cc(card) {

// Only change code below this line

if (card <= 6){

count ++;

} else if (card >6 && card <10 ){

count = count + 0;

} else 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";

} else

return count + " Hold";

// Only change code above this line

}

cc(2); cc(3); cc(7); cc('K'); cc('A');
``````
1 Like

thanks to everyone who responded i gave up hope now im back into it!!!

legends