Problem with java Code Counting Cards

Tell us what’s happening:
I can garantee that this code is corect but the system is not accepting as if it is correct it is telling me that it is wrong what should i change?

Your code so far
var n=card.length;
var prifati;
count=0;
var i=0;
for (i=0;i<n;i++){
if (2<=card[i] && card[i]<=6){
count++;
}
else if (7<=card[i] &&card[i]<=9){
count=count;
}
else if (card[i]==10 ||card[i]===“J” || card[i]===“Q”|| card[i]===“K”|| card[i]===“A”){
count–;
}
}
if(count<=0)
{
prifati=“Hold”;
}
else if(count>0) {
prifati=“Bet”;
}
return count+" "+ prifati;


var count = 0;

function cc(card) {
 // Only change code below this line
var n=card.length;
var prifati;
count=0;
var i=0;
for (i=0;i<n;i++){
if (2<=card[i] && card[i]<=6){
count++;
}
else if (7<=card[i] &&card[i]<=9){
 count=count;
}
else if (card[i]==10 ||card[i]==="J" || card[i]==="Q"|| card[i]==="K"|| card[i]==="A"){
count--;
}
}
if(count<=0)
{
 prifati="Hold";
}
else if(count>0) {
prifati="Bet";
}
return count+" "+ prifati;

 // Only change code above this line
}

cc(2); cc(3); cc(7); cc('K'); cc('A');
console.log(cc([2,3,4,5,10,"A"]))

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.163 Safari/537.36.

Challenge: Counting Cards

Link to the challenge:

The card argument to the cc function is a number or a string, it’s not an array.

2 Likes
var count = 0;
var holdBet;

function cc(card) {
  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;
    case 3:
    case 2:
    case "A":
    case "10":
    case "K":   
      count--;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":   
      count--;
      break;
  }
  if (count > 0){
    holdBet = 'Bet'
  }
  else {
    holdBet = 'Hold'
  }
  return  count +" "+ holdBet;}
cc(2); cc(3); cc(7); cc('K'); cc('A');

thx a lot but if it was an array this would be a good answer or i will have a problem?
p.s if i do it like the example bellow which the program says it is correct it will only work for the number that i have entered and it will not finish the work of counting cards because the point is to go up or down with every new card but this gives the value only on a single card which is not counting cards.

Hi @adallaureano, it’s great you solved the challenge, but we’re trying to avoid posting full solutions on the forum while we help others work through the solutions, so I’ve wrapped your solution in spoiler tags to blur it out unless clicked.

Cheers,
chuck

the function accepts a single card at a time, but for each card update a global variable, so the global variable keep tracks of the cards counted till now. The function update with last card and output what to do with last card shown (Hold or Bet)