lundi 25 octobre 2021

Trying freecodecamp question another way, coming back undefined

I have already completed this exercise in freecodingcamp but am trying it another way to. This is how I originally solved it.

var count = 0;

function cc(card) {
  // Only change code below this line

  if (card >= 2 && card <= 6){

    count ++ ;
  }

  else if (card == 10 || card == "J" || card =="Q" || card =="K" || card =="A" ){

    count --
  }


  if (count >= 1){
    return count + " Bet"}

    else return count + " Hold"; 


  
  // Only change code above this line
}



 cc(2); cc(3);  cc(7);  cc('K');  cc('A');

console.log(cc());

console.log(count);

Now I want to try and add the last part where it return count + bet or hold

if (count >= 1){
return count + " Bet"}

else return count + " Hold"; 

After each if statement but it comes back undefined. I know it's not the most efficient way but I just want to see if I can.

var count = 0;

function cc(card) {
  // Only change code below this line

  if (card >= 2 && card <= 6){

    count ++ 
  

   if (count >= 1){
    return count + " Bet"}

    else return count + " Hold";
  }

  else if (card == 10 || card == "J" || card =="Q" || card =="K" || card =="A" ){

    count --

     if (count >= 1){
    return count + " Bet"}

    else return count + " Hold";
  }


  

  
  // Only change code above this line
}



 cc(2);  cc(3);  cc(7);  cc('K');   cc('A');

console.log(cc());
console.log(count);

Thank you for any feedbac!

Aucun commentaire:

Enregistrer un commentaire