Created
March 24, 2014 23:24
Javascript Short-Hand IF Within Object Notation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
// Create an array of friends. | |
var arrFriends = new Array( | |
"Molly", | |
"Sarah", | |
"Dave", | |
"Luke" | |
); | |
// Get the day of the week. | |
var intDayOfWeek = (new Date()).getDay(); | |
// Figure out which friend to call based on | |
// the given day of the week. Call Luke on saturday. | |
// For every other day, call Molly (my girlfriend). | |
var strFriendToCall = arrFriends[ ( intDayOfWeek == 6 ) ? 3 : 0 ]; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment