Switch, Array, Object – Becoming Clearer

Trying to understand the switch function. I think I understand the basics but through further use should become clearer. 

var count = 2;

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){

        return count + ” Bet”;

      } else {

        return count + ” Hold”;

  // 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’);

I ended up copying and pasting this from the clues section so I could just move past it. Hoping compound learning will kick in.

Other things learnt:

  • An array just stores multiple values. 
  • Objects are arrays too but store many different pieces of information like this:

var car = {type:”Fiat”, model:”500″, color:”white”};

Also, you can use switch statement followed by if & else/if statements.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s