Tell us what’s happening:
I’m having trouble figure out the logic for this lesson.
Your code so far
var count = 0;
function cc(card) {
// Only change code below this line
if(card>=2 && card <=6){
count++;
return count + " Bet";
}
else if(card>=7||card<=9){
return count + " Hold";
}
else if (card==10||card=="J"||card=="Q"||card=="K"||card=="A"){
count--;
return count + " Hold";
}
return "change me" ;
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc(‘K’); cc(‘A’);
// running test
Cards Sequence 10, J, Q, K, A should return -5 Hold
Cards Sequence 2, J, 9, 2, 7 should return 1 Bet
Cards Sequence 2, 2, 10 should return 1 Bet
Cards Sequence 3, 2, A, 10, K should return -1 Hold
// tests completed Your browser information:
User Agent is: Google Chrome Version 68.0.3440.75 (Official Build) (64-bit)
This is what I have so far. It still doesn’t work because the last number in the test leaves from the “Hold” part of the program. I’m still confused how to set this up.
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(card>=2 && card <=6){
return count + " Bet";
}
else if((card>=7 && card<=9)||(card==10 || card=="J" || card=="Q" || card== "K" || card== "A")){
return count + " Hold";
}
return "Change Me";
// Only change code above this line
}
// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc(‘K’); cc(‘A’);
// running test
Cards Sequence 2, J, 9, 2, 7 should return 1 Bet
Cards Sequence 2, 2, 10 should return 1 Bet
// tests completed
I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.