Hi, may I know what is wrong with my code? Feels like I have misunderstood something but I am unable to find it. The code did not work.
Code:
let count = 0;
var names = ("Bet", "Hold");
function cc(card) {
// Only change code below this line
switch (card){
case 2:
case 3:
case 4:
case 5:
count ++;
break;
case 7:
case 8:
case 9:
count = count;
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count --;
break;
}
if (count > 0) {
return count + "" + names[0];
} else {
return count + "" + names[1];
}
// Only change code above this line
}
I’ve edited your code 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.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
It looks like maybe you were trying to do an array here. If so, you need to use the correct syntax.
You have only listed cases from 2-5 but the directions say 2-6
This is not the correct way to add a space between variables.
I would review the string lesson on how to correctly add spaces between variables so you can fix this.
Your input have been very useful thank you for pointing out the parts where I had problems with. Managed to run the code after amending the parts that you highlighted!
For those who have the similar idea of using array, here is the working code after some minor adjustments
let count = 0;
const names = ["Bet", "Hold"];
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 = count;
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count --;
break;
}
if (count > 0) {
return count + " " + names[0];
} else {
return count + " " + names[1];
}
// Only change code above this line
}