So I’m trying to figure out how to get the log to stop printing ’ bet/hold’ after EACH card. ‘break’ should make it move to the next card, but then how does it ever get to the if/else statement that prints the card count and bet/hold recommendation? Each iteration of the function includes the if/else statement that prints the count and recommendation - it makes sense that it would print something after EACH card. How would you get the function to perform only half the function until the very last use?
(I’m probably overthinking this.)
Your code so far
var count = 0;
function cc(card) {
// Only change code below this line
switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count--;
break;
}
if (count > 0) {
console.log(count + " Bet");
} else {
console.log(count + " Hold");
}
// Only change code above this line
}
cc(2); cc(3); cc(7); cc('K'); cc('A');
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36.
right, so I tried deleting the console.log commands in the if/else statement at the bottom, replaced them with return, and it worked. Seems like a cop-out. I’d still like to see the recommendation and the count in the log, y’know?
right, so I tried deleting the console.log commands in the if/else statement at the bottom, replaced them with return, and it worked. Seems like a cop-out. I’d still like to see the recommendation and the count in the log, y’know? Can i do return console.log? That would still print multiple instances of my count/recommendation though.
One last question - so say someone wants to use this little card-counting program - I’d have to do something in HTML/CSS, make somewhere they can pop their cards in, have this little JS thingo running in the background, and then display the function’s answer to the person reading the webpage, yeah? Actually printing the recommendation so it can be seen, is that more of a HTML/CSS consideration?
I apologise if this is out of the scope of the question or if I’m getting too far ahead of myself
Remember that html and css are for content and style.
Javascript is the programming language where you can create functionality and interactive moments on your website.
Once you dive deeper into the javascript curriculum and start working on this project idea than you will start to understand how all three of these languages work together to make this idea come to life.
And then if you get stuck on this project than you can create a new topic and ask your questions there.