Skip to content

Instantly share code, notes, and snippets.

@joannasese
Last active April 30, 2017 19:51
Show Gist options
  • Save joannasese/cd02dd3354efa77696d36bd097ea7676 to your computer and use it in GitHub Desktop.
Save joannasese/cd02dd3354efa77696d36bd097ea7676 to your computer and use it in GitHub Desktop.
Control flow: if, else-if, else
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Control flow: if, else-if, else">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Control flow: if, else-if, else</title>
</head>
<body>
<script id="jsbin-javascript">
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Control flow: if, else-if, else">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Control flow: if, else-if, else</title>
</head>
<body>
</body>
</html>
</script>
<script id="jsbin-source-javascript" type="text/javascript"><!DOCTYPE html>
<html>
<head>
<meta name="description" content="Control flow: if, else-if, else">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Control flow: if, else-if, else</title>
</head>
<body>
</body>
</html></script></body>
</html>
/*
CONTROL FLOW: IF, ELSE-IF, ELSE STATEMENTS
I enjoy if else statements because they make sense in this senseless world.
Here's the syntax:
*/
if (condition1){
statement1 if condition1 is true
} else if (condition2) {
statement2 if condition2 is true
}
else {
statement3 if all other conditions are true
};
/*
Javascript reads if/else statements from the top to bottom. In the example, if condition1 is not true, it will go down to the next condition.
Here it is in action:
*/
var cats = "mean";
if (cats = "mean"){
console.log("Cats are rude and scratch people.");
} else if (cats = "nice"){
console.log("Cats are just okay.");
} else {
console.log("Dogs are awesome!")
}
// prints -> "Cats are rude and scratch people."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment