# JS Counting Cards... using while or changing the order

I know… i’ve had search if anyone ask the same… but nothing…
I wonder why this isn’t right:

``````let count = 0;

function cc(card) {
// Only change code below this line
if (card > 0 && card < 7){
count++;}
else if(count === 10, "J", "Q", "K", "A"){
count--;}
while(count >6 && count < 10)
return "0 Hold";

if (count > 0) return count + " Bet";
else {
return count + " Hold";
}
}
``````

also doesn’t work if i use another “else if” instead of the while…

else if (count >6 && count < 10)
count–;

Can anyone explain me please?
Thanks

Yes, i was looking at this part of the instructions:
Cards Sequence 7, 8, 9 should return the string `0 Hold`

i still can’t understand :S How its the logic of each count-- after the conditionals. Are the numbers inside the IF / else part of the counter?

The switch solution: i would need a baby explanation

``````switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count--;
break;
}
if (count > 0) {
return count + " Bet";
} else {
return count + " Hold";
}
``````

Why the count++ after 6 and then the break? and then count-- after the letters…
I cant find the logic. I’m sorry all the question. This is the first real block i find in this workflow :S

Try using any if-else.

If Card === 2, then do what to count?

If Card === 3, then do what to count?

Explicitly handle every card value.

Then

If count ???, then return ???

else return ???

Don’t get fancy, don’t look at the answer

A linha:
else if(count === 10, “J”, “Q”, “K”, “A”){

não deveria ser:
else if(card === 10, “J”, “Q”, “K”, “A”){

???
Você pode postar os requisitos da função?

if (card > 0 && card < 7){
count++;}
else if (card = 7){
count = 0}
else if (card = 8){
count–}
else if (card = 9){
count–}
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";}

The solution seems going in the right direction but only this are ok:

• Passed: Your function should return a value for count and the text (`Bet` or `Hold`) with one space character between them.

• Passed: Cards Sequence 2, 3, 4, 5, 6 should return the string `5 Bet`

Passed: Cards Sequence 7, 8, 9 should return the string `0 Hold`

These are not comparison operators

``````  else if(count === 10, "J", "Q", "K", "A")
``````

right here is your problem but you are on the right track. you can do something like this by checking if the value of count is found in an array, or an object or a set.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.