Skip to content

Instantly share code, notes, and snippets.

@jpetto
Created August 21, 2012 20:07
Show Gist options
  • Save jpetto/3418960 to your computer and use it in GitHub Desktop.
Save jpetto/3418960 to your computer and use it in GitHub Desktop.
JavaScript syntax example
/*
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