Skip to content

Instantly share code, notes, and snippets.

@uniquename
Created July 21, 2017 12:44
Show Gist options
  • Save uniquename/9c0ee64c0f3288ff014be382441eb914 to your computer and use it in GitHub Desktop.
Save uniquename/9c0ee64c0f3288ff014be382441eb914 to your computer and use it in GitHub Desktop.
/**
* If Statements
*
* They have a condition, that is true or false.
* Think of them as boolean.
*/
var condition = true;
if (condition) {
// do something
}
/**
* If... else
*/
var isLoggedIn = true;
if (isLoggedIn) {
// do something
} else {
// do something else
}
/**
* If... else if... else (if)
*/
var someNumber = 5;
if (someNumber > 5) {
//console.log('is greater than 5');
} else if (someNumber < 5) {
//console.log('is smaller than');
} else {
//console.log('equals 5');
}
/**
* Operators
*/
/*
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
> greater than
< less than
>= greater than or equal to
<= less than or equal to
? ternary operator
*/
/**
* Switch statement
*
* If you want to test on more than on condition use switch
*/
//The getDay() method returns the weekday as a number between 0 and 6.
//If today is neither Saturday (6) nor Sunday (0), write a default message:
var date = new Date().getDay();
var text;
switch (date) {
case 1:
text = "Oh... Monday...";
break;
case 0:
text = "Today is Sunday";
break;
case 6:
text = "Today is Saturday";
break;
default:
text = "Looking forward to the Weekend";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment