Counting cards sollution

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');

how can i console a whole sequence?
i have a doubt. here , break is given after case2-case6
so it will keep incrementing until case 6 .like this-
(0+1+1+1+1+1) ?
now in case of case 10-case" string".
will the count value start from 0 or from 5?
my code

like console.log(cc(2), cc(3), cc(7), cc('K'), cc('A'));

no, there is only one single count++, so the number is increaseed only once

I don’t understand this question

this is empty and there is nothing to see


I’ve edited your post 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 (').


when you post a full working solution and have questions about it please surround it with [spoiler] and [/spoiler]

how can i console in such a way that values get added after every matching parameter?

what do you mean? what do you want to write to the console?

i want the output of sequence (2,3,4,5,6) to be 5?
but how can i console it in my editor using console.log?

do you mean you want to see the value of count only?
you can add console.log(count) inside the function or you can add console.log(count) after each function call

var count=0;
function cc(card) {
  switch(card) {
    case 2:
     
      
     case 3:
    
      
    case 4:
    
     
    case 5:
      
    case 6:
      count++;
      break;
      
      
  }
  return count;
}

1.i want to output a sequence in such a way that it return after being added at each cases?
for ex : for case2,case3,case4,case5,case6. it should return 5
(0+1+1+1+1+1)=5

so how can i console it?

use console.log after the sequence of function calls for that

cc(2); cc(3); cc(7); cc('K'); cc('A');
console.log(count)

bro,

cc(2); cc(3); cc(4); cc(5);
console.log(cc(6));

it is working, but i have putten the last value of the sequence in console.log.
then the desired result is coming?
can u tell me why?

the function outputs the value of count followed by Hold/Bet, so you are printing to the console the output of cc(6)

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