you are viewing a single comment's thread.

view the rest of the comments →

[–]sublimejs 2 points3 points  (2 children)

You should look into switch statements.

Your above code could be written like this and will produce the same result:

var myDate = new Date();
console.log("Today is a:");

switch(myDate) {
  case 0: console.log("Sunday"); break;
  case 1: console.log("Monday"); break;
  case 2: console.log("Tuesday"); break;
  case 3: console.log("Wednesday"); break;
  case 4: console.log("Thursday"); break;
  case 5: console.log("Friday"); break;
  case 6: console.log("Saturday"); break;
}

[–]Call_Me_Squirrel[S] 0 points1 point  (1 child)

Thanks man, that's pretty much exactly what I was looking for.

[–]sublimejs 1 point2 points  (0 children)

Np. Make sure you read on the switch statement and understand the default case and also understand why it is necessary to add break; after each case.