Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <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
- +If statements test if a condition is true, and execute something if
- true. */
- "use strict";
- var number = 8;
- function test1(num) {
- if (num > 5) {
- return "greater than five";
- }
- }
- console.log(test1(number)); //returns "greater than five"
- /* +If-else statements return something if the condition is met, and
- return something else if not met. */
- function test2(num) {
- if (num > 5) {
- return "greater than five";
- } else {
- return "less than five";
- }
- }
- console.log(test2(number)); //returns "greater than five"
- /*+Else-if statements test if a first condition is true, and if false
- evaluates a second condition. If neither are true, it executes the
- default, if written in, or nothing if not. */
- function test3(num) {
- if (num < 5) {
- return "less than five";
- } else if (num - 5 < 5) {
- return "not more than nine";
- }
- }
- console.log(test3(number)); //returns "not more than nine"
- /* +"else" can be used as a default to execute if none of the conditions
- are met. */
- function test4(num) {
- if (num < 5) {
- return "less than five";
- } else {
- return "greater than five";
- }
- }
- console.log(test4(number)); //returns "greater than five"
- /*+If statements can be nested, so that if the first condition is met,
- it will enter into the next if statement to test. */
- function test5(num) {
- if (num > 5) {
- if (num < 10) {
- return "greater than five but less than ten";
- }
- }
- }
- console.log(test5(number)); //returns "greater than five but less than ten"
- /* Conditions are always evaluated from top to bottom. Two or more
- conditions can also be combined into one test using logical operators. */
- function test6(num) {
- if (num > 0 && num < 10) {
- return "number between one and nine";
- }
- }
- console.log(test6(number)); //returns "number between one and nine"
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">/*Control flow: if, else-if, else
- +If statements test if a condition is true, and execute something if
- true. */
- var number = 8
- function test1(num) {
- if(num > 5) {
- return "greater than five";
- }
- }
- console.log(test1(number)); //returns "greater than five"
- /* +If-else statements return something if the condition is met, and
- return something else if not met. */
- function test2(num) {
- if(num > 5) {
- return "greater than five";
- } else {
- return "less than five";
- }
- }
- console.log(test2(number)); //returns "greater than five"
- /*+Else-if statements test if a first condition is true, and if false
- evaluates a second condition. If neither are true, it executes the
- default, if written in, or nothing if not. */
- function test3(num) {
- if(num < 5) {
- return "less than five";
- } else if(num - 5 < 5) {
- return "not more than nine";
- }
- }
- console.log(test3(number)); //returns "not more than nine"
- /* +"else" can be used as a default to execute if none of the conditions
- are met. */
- function test4(num) {
- if(num < 5) {
- return "less than five";
- } else {
- return "greater than five";
- }
- }
- console.log(test4(number)); //returns "greater than five"
- /*+If statements can be nested, so that if the first condition is met,
- it will enter into the next if statement to test. */
- function test5(num) {
- if(num > 5) {
- if(num < 10){
- return "greater than five but less than ten";
- }
- }
- }
- console.log(test5(number)); //returns "greater than five but less than ten"
- /* Conditions are always evaluated from top to bottom. Two or more
- conditions can also be combined into one test using logical operators. */
- function test6(num) {
- if(num > 0 && num < 10) {
- return "number between one and nine";
- }
- }
- console.log(test6(number)); //returns "number between one and nine"</script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement