Basic JS Card Counting

Tell us what’s happening:
Hello i was trying to make this card counting challenge but im stuck little bit i don t why my else if statement dose not work properly and how can i compare if value is equal to a string. Thank you!

Your code so far

var count = 0;

function cc(card) {
// Only change code below this line
if (card > 1 || card < 6) {
count++;
} else if(card === 10 || card === ’ ') {
count–;
console.log(‘work dam it!!’);
} else if (count > 0){
return count + " Bet";
} else {
return count + " Hold";
}

// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(‘a’); cc(‘k’); cc(‘s’);
console.log(count);

If you write it like this it is ‘if card is more than 1 OR less than 6’, so cards 2,3,4,5,6,7,8,9,10 will make the count raise.
You need an AND operator &&

Write count--; instead

If you don’t fix the previous one, you will not execute this when card is 10, also, card === ' ' means “card is a space”, change it to work when card is A, Q, J or K

If you use else if it will work only f previous statements were not executed, make it a separated if statement

2 Likes

idea of this part is that if card is equal do 10 or a string it should decrement count value ’ else if(card === 10 || card === ’ ') ’ ; but i dont understand how can i compare a number to a string type.

Thank you!

You need to specify each card separately if you use that way
Otherwise you need this:

1 Like

yeees that was what i was looking for thanks!