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.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
let count = 0;
function cc(card) {
console.log('\ncalling with card:', card)
switch (card) {
case 2:
console.log('* match 2')
count ++;
case 3:
console.log('* match 3')
count ++;
case 4:
console.log('* match 4')
count ++;
case 5:
console.log('* match 5')
count ++;
case 6:
console.log('* match 6')
count ++;
case 7:
console.log('* match 7')
count += 0;
case 8:
console.log('* match 8')
count += 0;
case 9:
console.log('* match 9')
count += 0;
case 10:
console.log('* match 10')
count --;
case "J":
console.log('* match J')
count --;
case "Q":
console.log('* match Q')
count --;
case "K":
console.log('* match K')
count --;
case "A":
console.log('* match A')
count --;
break;
}
if (count > 0) {
return count + " " + " Bet";
} else {
return count + " " + "Hold";
}
}
console.log(cc(2));
console.log(cc(3));
console.log(cc(4));
As always, check to docs. Seriously, always, always, always check the docs. Google “MDN switch” and read that. Especially about halfway down is a section on “Multi-case: single operation” - that’s going to be very useful.
By simplifying your code and using mulit-case and adding in a few breaks, I was able to get your code to work. There’s also a slight issue with the spacing on the output strings.
I thought that i had to inserti multiple data like console.log((2, 3, 4, ...));
in that case is everything more simple with only one , done.
thank you for your advice sir, if you can clarify just the last think to me I would appreciate it.
counting today I have been looking for a way to make the program accept a multiple insertion for 3 days, what should I have done to make it?
If the function were set up that way, sure. But the way this function is written, it can only handle one parameter:
function cc(card) {
It will take one parameter, the first one. You could accept the second argument like:
function cc(card, card2) {
You could build this out this way, but you’d have to know the max number of cards. There are also ways to deal with variable numbers of parameters that you will learn later. In theory, you could write this function to do that, handle a variable number of parameters. But as written it can’t and it isn’t part of the assignment.
counting today I have been looking for a way to make the program accept a multiple insertion for 3 days, what should I have done to make it?
Again, the assignment is to handle one at a time. Finish that. Once you get that done, if you want, we can have some fun and make it work for a variable number of inputs.