Help with this card counting challengeX,

Tell us what’s happening:

I am a newbie and getting frustrated with this challenge as i can not move forward,Please help.

Your code so far


var count = 0;

function cc(card) {
// Only change code below this line
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;
}
var holdbet = 'Hold'
if(count > 0) {
holdbet = 'Bet'
}

return count + "" + holdbet;
// Only change code above this line
}

cc(2); cc(3); cc(4); cc(5); cc(6);
console.log(cc(4));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36.

Challenge: Counting Cards

Link to the challenge:

You will write a card counting function. It will receive a card parameter, which can be a number or a string, and increment or decrement the global count variable according to the card’s value (see table). The function will then return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative. The current count and the player’s decision ( Bet or Hold ) should be separated by a single space.

Take a closer look at the result you are getting from function (i.e. via console.log(cc(4));) , how it differs from the example outputs?

I am sorry but i am dumb when it comes to understanding, is there any link to the solution to this challenge,

Example outputs from the challenge description:

-3 Hold
5 Bet

While when calling your function (console.log(cc(4))) result looks like this:

6Bet

What needs to be changed to make it look similarly to the examples?

1 Like