Counting Cards between diffrence

Counting Cards between diffrence
0

#1

Tell us what’s happening:

Your code so far

var count = 0;

function cc(card) {
  // Only change code below this line
 
if (card  >1&&card <7){ 
count=count+1 ;}
  else if (card == 10||card== 'J'||card== 'Q'||card== 'K'||card== 'A'){
count=count-1; }
  else if (card ==7,8,9){
    count+=0;
  }

if (count>0){
  result= count + ' Bet';
}else {
  result= count + ' Hold';
}

return result;

  
  // 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:
Only the last will display
why Cards Sequence 3, 7, Q, 8, A should return "-1 Hold"
Cards Sequence 10, J, Q, K, A should return “-5 Hold” (the last is same)?

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

Link to the challenge:


#2

the last return you can erase it.the second if else is not need it


#3

What do your mean?

Because for 3 you add 1 to count, so count is 1. For 7 you add zero to count, so count is still 1. For Q, you subtract 1 from count, so count is 0. For 8 you add zero to count, so count is still 0. Finally, for A you subtract 1 from count, so count is -1

What do you mean by the last is same?


Also, your posted solution is a complete (passes all tests) solution, so I have blurred it out to not spoil the final solution for someone who clicks on your post that does not want to see a completed solution immediately.

#5

Too awesome, your answer is perfectly solved my problem, thank you very much!


#6

thanks your useful suggestion