Visit Counting Cards

Hi, may I know what is wrong with my code? Feels like I have misunderstood something but I am unable to find it. The code did not work.

Code:

let count = 0;
var names = ("Bet", "Hold");

function cc(card) {
  // Only change code below this line

switch (card){
  case 2: 
  case 3: 
  case 4:
  case 5:
    count ++;
    break;
  case 7:
  case 8:
  case 9:
    count = count;
    break;
  case 10:
  case "J":
  case "Q":
  case "K":
  case "A":
    count --;
    break;   
}

if (count > 0) {
  return count + "" + names[0];
} else {
  return count + "" + names[1];
}
  // Only change code above this line
}

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Hi @Pinocchio !

Welcome to the forum!

It looks like you have a few issues here

It looks like maybe you were trying to do an array here. If so, you need to use the correct syntax.

You have only listed cases from 2-5 but the directions say 2-6

This is not the correct way to add a space between variables.
I would review the string lesson on how to correctly add spaces between variables so you can fix this.

Hope that helps! :+1:

Thank you for pointing that out. After referring back to the curriculum , I have managed to refresh on the array part.

Your input have been very useful thank you for pointing out the parts where I had problems with. Managed to run the code after amending the parts that you highlighted!

For those who have the similar idea of using array, here is the working code after some minor adjustments

let count = 0;
const names = ["Bet", "Hold"];

function cc(card) {
  // Only change code below this line

switch (card){
  case 2: 
  case 3: 
  case 4:
  case 5:
  case 6:
    count ++;
    break;
  case 7:
  case 8:
  case 9:
    count = count;
    break;
  case 10:
  case "J":
  case "Q":
  case "K":
  case "A":
    count --;
    break;   
}

if (count > 0) {
  return count + " " + names[0];
} else {
  return count + " " + names[1];
}
  // Only change code above this line
}

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