basic java script card counting
can any one help i been trying but is not working.
basic java script card counting
can any one help i been trying but is not working.
Link? Code? what have u tried so far?
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 ++;
break;
case 7:
case 8:
case 9:
count --;
break;
}
var holdbet = 'Hold';
if (count > 0){
holdbet = 'bet'
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.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>
) will also add backticks around text.
Note: Backticks are not single quotes.
1- are you sure this is your whole code? there seems to be stuff missing
2- what’s the challenge link?
3- what do the failing tests say?
3bis- do you understand why they are failing?
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 ++;
break;
case 7:
case 8:
case 9:
count --;
break;
}
var holdbet = 'Hold';
if (count > 0){
holdbet = 'bet'
}
return count + "" + holdbet;
// 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');
below is the challenge
You will write a card counting function. It will receive a card
parameter, which can be a number or a string, and increment or decrement the global count
variable according to the card’s value (see table). The function will then return a string with the current count and the string Bet
if the count is positive, or Hold
if the count is zero or negative. The current count and the player’s decision ( Bet
or Hold
) should be separated by a single space.
you did not answer any of my questions
even if now it seems your code is not missing anything
also please format your code as shown above
5- do you know what your function is returning? try using console.log()
and here is the link to the challenge
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/counting-cards
what about cards 10
, J
, Q
, K
, A
?
even after changing them it did not work but let me try again and see
the codes need to do:
2 : count = 1 [ 2, 3, 4, 5, 6 ] + 1
4 : count = 2 [ 2, 3, 4, 5, 6 ] + 1
8 : count = 2 [ 7, 8, 9 ] + 0
J : count = 1 [ 10, J, Q, K, A ] - 1
3 : count = 2
return value is…
count = 2 [positive number]
2 Bet
ok let me try and see