Build a Card Counting Assistant - Build a Card Counting Assistant

Tell us what’s happening:

I am not sure if this is going to the forum again. I tried to post it once but I could not find it. I don’t know whats going wrong. Am I using the ++ signs incorectly cos that is where it says unexpected token?

Your code so far

let count = 0 

function cardCounter(card){
  if (card === 2 || card === 3 || card === 4 || card === 5 || card === 6){
    count ++
  }
 if else (card === 10 || card === "J" || card ==="Q" || card === "K" || card === "A"){
   count --
 }

 if (count <= 0){
   return `${count} Bet`
 }
 else if (count >= 1){
   return `${count} Hold`
 }

  console.log(cardCounter(8))
  



Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Build a Card Counting Assistant - Build a Card Counting Assistant

the issue is here, are you sure that it is if else?

should it be else ? because that’s not working either

I changed to else if and it is still not working

post your updated code please

but the other thing you need to fix, is, where does your function end?

let count = 0

function cardCounter(card){

if (card === 2 || card === 3 || card === 4 || card === 5 || card === 6){

count ++

}

else if (card === 10 || card === “J” || card ===“Q” || card === “K” || card === “A”){

count –

}

if (count <= 0){

return `${count} Bet`

}

else if (count >= 1){

return `${count} Hold`

}

console.log(cardCounter(8))

where does your function end?

you can right click inside the editor and choose the format option, you can see the issue there too

Sorry for being thick. I still don’t understand what I have to do to end a function. I thought it ended with the } symbol

so I’ll have to write return on the end?

at the end you have a} , but isn’t that for the else if?

so where is the one for the function?

let count = 0

function cardCounter(card) {

if (card === 2 || card === 3 || card === 4 || card === 5 || card === 6) {

count++

}

else if (card === 10 || card === “J” || card === “Q” || card === “K” || card === “A”) {

count–;

}

if (count <= 0) {

return `${count} Bet`

}

else if (count >= 1) {

return `${count} Hold`

}

}

console.log(cardCounter(8))

It is still not working or did I put it in a wrong place?

Also thank you so much for helping.

oh now I think I just have to finnish the thing. Thank you a million for helping me. I’ll be back if I still manage to mess it up. But thank you a lot for that. It really made me understand functions better.

good job! it seems you figured it out

boy was I wrong. I mean you did help me figure out the end of a function and more of how the function works. And I will be for ever grateful for that but my code is still not working. It is finally giving me something but it is only telling me to hold.

let count = 0



function cardCounter(card) {

if (card === 2 || card === 3 || card === 4 || card === 5 || card === 6) {

count ++

  }

else if (card === 10 || card === "J" || card === "Q" || card === "K" || card === "A") {

count --;

  }




if (count <= 0) {

return `${count} Bet`

  }

else if (count >= 1) {

return `${count} Hold`

  }

}




console.log(cardCounter(2))

console.log(cardCounter(3))

console.log(cardCounter(4))

console.log(cardCounter(5))

console.log(cardCounter(6))

console.log(cardCounter(7))

console.log(cardCounter(8))

console.log(cardCounter(9))

console.log(cardCounter(10))

console.log(cardCounter("J"))

console.log(cardCounter("Q"))

console.log(cardCounter("K"))

console.log(cardCounter("A"))

This is what it gives me
1 Hold
2 Hold
3 Hold
4 Hold
5 Hold
5 Hold
5 Hold
5 Hold
4 Hold
3 Hold
2 Hold
1 Hold
0 Bet

I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

maybe review the last two user stories about how to choose between Bet and Hold

can you point out why one of these work and the other does not? I found a problem on the hints section that I could get working with deleting a part but my version is still not working.

Not Working 

```let count = 0

function cardCounter(card) {
  if (card === 2 || card === 3 || card === 4 || card === 5 || card === 6) {
    count++;
  }
  else if (card === 10 || card === "J" || card === "Q" || card === "K" || card === "A") {
    count--;
  }


  if (count < 0) {
    return `${count}` + " Bet";
  }
  else if (count <= 0) {
    return `${count}`+ " Hold";
  }
}
```
let count=0;
 function cardCounter(card)
 {
  if(card === 2 || card === 3 || card === 4 || card === 5 || card === 6)
   {
       count ++;
   }
   
    else if(card==10|| card=="J"|| card=="Q"|| card=="K"|| card=="A")
   {
       count--;
   }
 
  if (count > 0) {
    return `${count}` +  " Bet";
  } else if (count <= 0){
    return `${count}` + " Hold";
  }
}``` Working. Also I dont know if I'm using this the right way. 

For some reason I cant find the major difference why the other keeps not working.

which of these two is going to return a value for positive values of count?