Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!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>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- //Control flow: if, else-if, else
- /* Allows to control the flow of an application.
- * Decisions are made in code by asking true or false questions.
- * Based on the answer, we decide what code runs if a statement
- * is true or false/
- */
- //IF, ELSE-IF, AND ELSE STATEMENTS
- /* To start a conditional, you use an IF statement.
- * You can chain as many ELSE IF statements as needed to initial
- * IF statement. The default ELSE statement is appended at the end of
- * the chain.
- *
- *
- * Anatomy: 1. Test condition in (). 2. BODY {} executed when condition
- * is true. BRACKETS MATTER AND INDENTATION IS CONVENTION
- */
- var condition = true;
- if(condition === true) {
- //do something if condition is true
- } else {
- //do something if condtion is false
- }
- /* More questions can be chained together to give more options
- * to program flow.
- */
- var color = "white";
- if(color === "white") {
- //do something
- } else if(color === "blue") {
- //do something
- } else {
- //do something
- }
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">//Control flow: if, else-if, else
- /* Allows to control the flow of an application.
- * Decisions are made in code by asking true or false questions.
- * Based on the answer, we decide what code runs if a statement
- * is true or false/
- */
- //IF, ELSE-IF, AND ELSE STATEMENTS
- /* To start a conditional, you use an IF statement.
- * You can chain as many ELSE IF statements as needed to initial
- * IF statement. The default ELSE statement is appended at the end of
- * the chain.
- *
- *
- * Anatomy: 1. Test condition in (). 2. BODY {} executed when condition
- * is true. BRACKETS MATTER AND INDENTATION IS CONVENTION
- */
- var condition = true;
- if(condition === true) {
- //do something if condition is true
- } else {
- //do something if condtion is false
- }
- /* More questions can be chained together to give more options
- * to program flow.
- */
- var color = "white";
- if(color === "white") {
- //do something
- } else if(color === "blue") {
- //do something
- } else {
- //do something
- }
- </script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement