Javascript blackjack Counting Cards

Javascript blackjack Counting Cards
0.0 0

#1

Tell us what’s happening:
I’m trying to do this without directly looking for the answer. so this is what i’ve done so far…
can anybody give me a hint what i did wrong ?
Thanks in advance./

Your code so far


var count = 0;

function cc(card) {
  // Only change code below this line
  if (card >=2 && card <=6){
    count += card;
    return  count + " Bet";
  }else if(card >=7&& card <=9){
    count += card;
    return count + " Hold";
  }else if (card ==10||card =='J'||
  card == 'Q'||card =='K'||card =='A'){
    count += card;
    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(7); cc('K'); cc('A');

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/counting-cards


#2

You don’t add card to the count. The specific values to add are listed under the instruction.


#3

I will give you a small hint by asking you a question.

If a card is a 2, 3, 4, 5, or 6 how much should the value of the count variable change? Once you answer this question, look at the value you are adding to the count variable for the applicable if statement.


#4

var count = 0;

function cc(card) {
// Only change code below this line
if (card >=2 && card <=6){
count += 1;
return count + " Bet";
}else if(card >=7&& card <=9){
count += 0;
return count + " Hold";
}else if (card ==10||card ==‘J’||
card == ‘Q’||card ==‘K’||card ==‘A’){
count -= 1;
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(7); cc(‘K’); cc(‘A’);


// running test
Cards Sequence 2, J, 9, 2, 7 should return 1 Bet
Cards Sequence 2, 2, 10 should return 1 Bet
// tests completed

this is what i’ve got so far.
Am I close to the answer or should i re write it all over again?


#5

Thank you. but I’m still stuck :frowning:


#6

You need to separate the logic of adding and subtracting the count from what actually gets returned. Currently, you are only return the count + " Bet" when cards are a 2, 3, 4, 5, or 6. What gets returned is only dependent on the count value, just like the count value is only dependent on the card values. You have the same issue with the other two returns.