Basic JavaScript - Counting Cards

I chose to make variables with an array of the possible card outcomes.

I know there is a lot of unnecessary work in here but I’m sure i’m missing something big that needs reworked.

  **Your code so far**
let count = 0;

function cc(card) {
// Only change code below this line
let addOne = [2, 3, 4, 5, 6];
let addZero = [7, 8, 9];
let subtractOne = [10, "J", "Q", "K", "A"];
if (card == addOne){
count++;
} else if (card == addZero){
count;
}else if (card == subtractOne){
count--;
} 
if (count <= 0){
return count + " Hold"
}else{
return count +  " Bet"
}
// Only change code above this line

}
cc(2); cc(3); cc(7); cc('K'); cc('A');

Challenge: Basic JavaScript - Counting Cards

Link to the challenge:

Hi Don,

In practice, the == is not going to be useful almost ever . In this case in particular, what you actually want to know is whether the card value matches an element within an array. It is possible to make more direct comparisons or try to find a JavaScript method for arrays that fulfills your requirements here. I won’t give it away but this might be worth practicing your research skills.

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