What's wrong with this code? Ex. 81-BlackJack.js

Hey, how are you all? I’m going through the JS course and in this exercise this solution is not working, but can’t understand why… Can you explain it to me please?

  // Only change code below this line
  if (card >= 2 || card <= 6) {
    count = count + 1
  } else if (card >= 7 || card <= 9) {
    count = count + 0
  } else (card == 10, 'J', 'Q', 'K', 'A'); {
    count = count -1
  }


if (count <= 0) {
  return count + 'Hold'
} else (count >= 1); {
   return count + 'Bet'
}
  // Only change code above this line
}

Thank you!

I know that I can use count++ or --, also I know that I just wasted time writing + 0, realize it later when I saw the solution haha

Can you provide a number that is not greater than or equal to 7 OR less than or equal to 9? Does 10 work there?

Even changing that mistake, is still wrong for something else that I cannot tell :smiling_face_with_tear:

How did you change the code?

Else statements do not have conditions.

Just commented those lines, to ignore them.

  if (card >= 2 || card <= 6) {
    count = count + 1
  /*} else if (card >= 7 || card <= 9) {
    count = count + 0*/
  } else (card == 10, 'J', 'Q', 'K', 'A'); {
    count = count -1
  }

This has two issues

  1. else doesn’t take a condition

  2. that is not how you check for multiple values

This is not at all a valid fix

Gotcha, I’ll rewrite the else statements, but why not comment out some lines to try if the problem is there? How would you do it? It’s my first step in order to fix what’s wrong, comment sth out and see what happens

Bro, check this out in the official hint/solution there’s an else if condition… So now I’m even more confused than before hahah, I think I rather get poisoned by a snake :joy: :sweat_smile:

Bro I know the guide solution (not really official) has an if-else. I never said you couldn’t use an if-else for this problem, just that your if-else conditions were written incorrectly.

I thought you mean in general. Could be that ‘else’ doesn’t take but ‘else if’ does? Or I’m not understanding what you mean? Thanks for replaying tho

An else statement doesn’t use a condition.

This is still giving me an unexpected output. The console says -2, but in my thinking it must be 0… Can’t see the problem, really. It’s the same damn code that the hint!

let count = 0;

function cc(card) {
  // Only change code below this line
  if (card >= 1 || card <= 6) {
    count = count + 1

  } else if (card == 10, 'J', 'Q', 'K', 'A'); {
    count = count -1
  }


/* if (count <= 0) {
  return count + 'Hold'
} else if (count >= 1); {
   return count + 'Bet'
} */
  // Only change code above this line
}
cc(2); cc(3); cc(7); cc('K'); cc('A');
console.log(count)

This range contains literally every singe number.

This is not how you compare against multiple values.

Also, adding the ; there breaks the if statement body away from the if statement condition, meaning that the body always runs.