Created
August 21, 2012 20:07
-
-
Save jpetto/3418960 to your computer and use it in GitHub Desktop.
JavaScript syntax example
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
/* | |
A multi-line comment | |
Program Description: | |
A script that will display an alert box on Tuesday. Hot stuff. | |
*/ | |
// declare variable | |
var current_day; | |
// create a function | |
var get_current_day = function() { | |
// declare function variables | |
var today; | |
var day_of_the_week; | |
// assign values to function variables | |
today = new Date(); // object instantiation | |
day_of_the_week = today.getDay(); // object method call | |
// send back the current day of the week | |
return day_of_the_week; | |
}; | |
// store current day of the week in a variable | |
current_day = get_current_day(); | |
// branching statement, block signified by curly braces | |
if (current_day === 2) { | |
// method call | |
alert("It's Tuesday. Time to write some code."); | |
} else { | |
alert("It's not Tuesday. Time to study some code."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment