Question on testing my javascript in the the lessons

For counting cards Javascript lesson, I was able to pass all of the tests using this code I wrote:

var count = 0;

function cc(card) {
switch(card) {
case 2 :
case 3 :
case 4 :
case 5 :
case 6 :
  count += 1;
  break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count -= 1;
}

var result = ("");

if (count >= 1){
result = (count + " " + "Bet")}
else if (count <= -1){
result = (count + " " + "Hold")}
if (count == 0){
result = (count + " " + "Hold")
}
return result }

However, when I put at the end this: console.log(cc(2, 3, 4, 5, 6));

it gives me 1 Bet, when it should give me 5 Bet.

Is there a way to use console.log properly so I can test the code I’ve written using my own inputs into the function?

I put this at the end and it works! Thank you!!

@RandellDawson Is this what you meant?

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

That works too.

I meant:

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

You could also do something like:

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

That makes sense, thanks for explaining!

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