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
}
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
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.
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)