Counting Cards in JS

Counting Cards in JS
0.0 0

#1

Tell us what’s happening:
Here while i code like this,it works and gives me the output.There are 7 examples in task.I can clear all of them using my code that is little bit differ from actual code shown in hint.
The output is exactly same it should be wanted…

Your code so far

var x=0;
  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=1;
      x=x+count;
      break;
      case 10:case "J":case "Q":case "K":case "A":
      count=-1;
      x=x+count;
      break;
  }
  if (x <= 0){
    return x+" Hold";
  }
else {
       return x+ " Bet";
  }
  // Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(4); cc(5); cc(6);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0.

Link to the challenge:



#2

The instructions state:
You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card’s value (see table).

Your solution does not increment or decrement the count variable. Instead you assign it either 1 or -1 and then have created another variable x to hold the actual count for displaying purposes.

The problem is, there is specific reason they wanted you to increment or decrement. It is because the tests actually look at the value of count (and not x’s value) as part of the test.

You do not need the extra variable x anyway. You can simply add or subtract 1 to/from count inside for the different cases.


#3

Simply man, i know that there are many solution for this problem(may be simple or wise ) But i have to know that why is it shown as wrong even though i got the resultant output…