Counting cards problem,

Tell us what’s happening:
I couldn’t find the error in the code, each item when fn calls it returns a value instead of returning in the final .kindy 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;
   
}

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


// Only change code above this line
}

cc(2); cc(3); cc(7); cc('K'); cc('A');
  **Your browser information:**

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

Challenge: Counting Cards

Link to the challenge:

add a console.log statement to check the output of your function and confront it with the expected output

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";}

Hi @gokul47

The code is just missing spaces in front of the ‘Bet’ and ‘Hold’ :grinning:

Thanks,
Cam

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Hi @ilenia ,

Noted, will keep that in mind in future!

Thanks,
Cam

Tell us what’s happening:
guys!!!
why isn’t return count+ is not being called every time when the fn is called, and if statement only works after the last fn call??
this code below give me a correct and,but why if stmt is not working everything when fn called?break;; is there in switch but it only break from loop ?
i put this code in VSCODE with return replaced with console.log, it return count+ every time when fn called!!

  **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;
   
}

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


// Only change code above this line
}

cc(2); cc(3); cc(7); cc('K'); cc('A');
  **Your browser information:**

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

Challenge: Counting Cards

Link to the challenge:

have you tried adding a console.log statement to your code?

also, are you sure it gives the correct result?

console.log(cc(2));   // '1 Bet'
console.log(cc(3));   // '2 Bet'
console.log(cc(7));   // '2 Bet'
console.log(cc('K')); // '1 Bet'
console.log(cc('A')); // '0 Hold'

the comments have the expected outputs

add a console.log statement in your code and confront, they need to match exactly

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