Welcome to the Tutorial Site!



There are 3 main conditionals we will talk about here!

  1. If statements
  2. if else statements
  3. if statements

An if statement is pretty basic, and just tells us "if ______ is true then, run this code." This can be very useful for running code to check for certain things, and to print or organize an action if the value is true. In very simple if statements, we can just compare two numbers. This can be used to reference functions to create more widely useful code.)


                    if(3 > 1) {
                        console.log("Three is greater than one.");
                    }
                    
We can also add an else onto the if statement at the end, which allows us another option for if the if statement does not print true. In this way we can still have the code do an action as opposed to just doing nothing when the if statement returns as false.

                    if(3 < 1) {
                        console.log("Three is greater than one.");
                    } else {
                        console.log("This is not a true statement)
                    };
                    
                    //the second console.log would run in this case
                    
Going even further forward, we can add more possibilities with the else if statement. With this, we can add more possible conditions to be met, and actions to be executed if the conditions are met.

                    if(3 = 4) {
                        console.log("Three is greater than one.");
                    } else if(3 <= 4) {
                        console.log("Three is less than or equal to four.")
                    } else {
                        console.log("None of these statements are true.")
                    }